\Device\NUL
I mean if eax contains the address
It should be lea eax, [ptr + 4] then.
\Device\NUL
First, it will load the address value into eax. The eax value added 4 value. Load the arithmetic result to original address again.
\Device\NUL
I guess it's some x86 ABI ...
/
It should be lea eax, [ptr + 4] then.
But i dont understanded how to use restrict
𝑪𝒐𝒃𝒓𝒂
How to practice c++
\Device\NUL
But i dont understanded how to use restrict
https://en.cppreference.com/w/c/language/restrict
Mohamed
Write a C++ program to add two 4-bit binary numbers (without IF or DO or loops )? 😓😓😓 help me i can not solve the carry part in summation
\Device\NUL
I know
Show your code then
/
Show your code then
Now i will take the coputer
DaviChan
Write a C++ program to add two 4-bit binary numbers (without IF or DO or loops )? 😓😓😓 help me i can not solve the carry part in summation
Sudo code: num1 = 1011 num2 = 0010 res; crry; for(i++ < 4){ crry = !((num2[i]+num1[i])%2); res[i] != crry; }
DaviChan
So yeah, just resolve the loop by writing this 4 times
DaviChan
or use goto
DaviChan
I know, i was too lazy 😂
DaviChan
just write it 4 times 😅😅
Mohamed
no
DaviChan
Soory, i can write proper c++ code kater 😂
Mohamed
user will put 2 nums
Mohamed
in binary ... so you will read digits from user ...then calculate them manually using the RAW CODE
DaviChan
Sorry, i dont get that 🤔
DaviChan
The first part, yes 2 binary numbers, likely inputted as ascii characters
Mohamed
I MEAN ...you will make the hole function
DaviChan
a + b;
True just use an uint8 and set the bytes bases on the input and then just add it with the build in + operator 🤷🏻‍♂️👌
Mohamed
lets say ..... A1,A2,A3 ,A4 the first digits in memory ...B1,B2,B3,B4 the second ...C1 C2 C3 C4 the result ....and the user put 1011 for A and 1101 for B
Mohamed
so if we used the normal sum (+) you will get 2112
DaviChan
yes. I forgot to add the carry in lol
Mohamed
the question here how to use the modulus or the integer division to get the binary result
DaviChan
use %2 on each digit
Mohamed
res should be 10000
DaviChan
for the carry. Uhm lets think
Mohamed
ok very good ... then how to carry one ?
DaviChan
The carry is : result/2
Mohamed
lets say C1 = 0 =result
DaviChan
Yes?
Mohamed
DaviChan
Yes 👌
Mohamed
Yes 👌
the carry should be one ...added to the second bit
DaviChan
0/2 = 0 1/2 = 0 2/2 = 1 3/2 = 1
DaviChan
and the res will be: 0%2 = 0 1%2 = 1 2%2 = 0 3%2 = 1
DaviChan
So that is all you need for each digit
DaviChan
the starting point you get by num1[i]+num2[i]+carry
DaviChan
Where carry is initialized to 0 ofc.
DaviChan
To sum up. For each digit you do:
DaviChan
0/2 = 0 1/2 = 0 2/2 = 1 3/2 = 1
Then this to calculate the new carry
DaviChan
and the res will be: 0%2 = 0 1%2 = 1 2%2 = 0 3%2 = 1
Then this to get the result in base 2
DaviChan
Ill have time to write a proper short snippet later 😅
DaviChan
ill need to find a way around the loop limitation. I guess recursion and goto is also forbidden?
ببب ب
how should I structure my usb driver? more specifically I don't really have a clear picture of how does something like an usb keyboard driver use the base usb driver to periodically put in a new td to the queue or renew the existing one or should the base driver renew the tds in the periodic queues in the completion interrupt or something and should there be some list of free tds and queues and do you actually need nested queues or could you just have the base queues with specific intervals and the control, bulk and iso queues I guess the driver or whatever creates the td could take care of allocating and freeing it and then internally have some buffer of tds and then if its wants to renew the td it inserts a new one and then maybe the driver can also register a function that gets called when an usb interrupt occurs so it has a chance to check if the td was completed and renew it and do other stuff I guess having nested queues can make inserting new tds faster if you only put full queues in the main queues but then it has the problem that queues don't get automatically "removed" (atleast as far as I can tell) eg. if you have a queue with the element ptr pointing to another queue then the toplevel queue's element ptr doesn't get set to the last child queues td's link field but instead its only updated to the lowest level queue and then you would have to basically loop through all the queues in the usb int two times to remove the empty ones first looping until you get to the most lowest level queue and then going upward deleting the queue if its head and element has the terminate bit set and doing that every frame doesn't seem like a good idea so maybe its faster to just have the toplevel queues element pointer point directly to tds and ig you could also store the last tds address after the queue to keep the insertion of new tds or td chains fast but then what happens if the controller is just executing the last td when I insert a new td chain into there, because then the element ptr is still pointing to the last td so I am trying to insert it into the last one but then if it gets it done while I am calculating the last td address before its link ptr is set to anything, then the newly inserted td just doesnt get executed and it can't be solved by adding another check of the element ptr since then theres even more points where it may fail so it doesn't really work either if I am right with child queues it works but then there is the problem of removing the empty ones and if you would were to remove the empty ones in the usb int somehow it would be problematic if you are inserting a new queue when the cpu got interrupted how do I insert new tds without having the risk of it getting skipped without stopping the controller basically as I can't keep on inserting new queues after each other linked with the head link ptr because then they are just going to be leaved there and leak memory because you can't safely remove them if there can be other queue attached after it
ببب ب
how should I structure my usb driver? more specifically I don't really have a clear picture of how does something like an usb keyboard driver use the base usb driver to periodically put in a new td to the queue or renew the existing one or should the base driver renew the tds in the periodic queues in the completion interrupt or something and should there be some list of free tds and queues and do you actually need nested queues or could you just have the base queues with specific intervals and the control, bulk and iso queues I guess the driver or whatever creates the td could take care of allocating and freeing it and then internally have some buffer of tds and then if its wants to renew the td it inserts a new one and then maybe the driver can also register a function that gets called when an usb interrupt occurs so it has a chance to check if the td was completed and renew it and do other stuff I guess having nested queues can make inserting new tds faster if you only put full queues in the main queues but then it has the problem that queues don't get automatically "removed" (atleast as far as I can tell) eg. if you have a queue with the element ptr pointing to another queue then the toplevel queue's element ptr doesn't get set to the last child queues td's link field but instead its only updated to the lowest level queue and then you would have to basically loop through all the queues in the usb int two times to remove the empty ones first looping until you get to the most lowest level queue and then going upward deleting the queue if its head and element has the terminate bit set and doing that every frame doesn't seem like a good idea so maybe its faster to just have the toplevel queues element pointer point directly to tds and ig you could also store the last tds address after the queue to keep the insertion of new tds or td chains fast but then what happens if the controller is just executing the last td when I insert a new td chain into there, because then the element ptr is still pointing to the last td so I am trying to insert it into the last one but then if it gets it done while I am calculating the last td address before its link ptr is set to anything, then the newly inserted td just doesnt get executed and it can't be solved by adding another check of the element ptr since then theres even more points where it may fail so it doesn't really work either if I am right with child queues it works but then there is the problem of removing the empty ones and if you would were to remove the empty ones in the usb int somehow it would be problematic if you are inserting a new queue when the cpu got interrupted how do I insert new tds without having the risk of it getting skipped without stopping the controller basically as I can't keep on inserting new queues after each other linked with the head link ptr because then they are just going to be leaved there and leak memory because you can't safely remove them if there can be other queue attached after it
Maybe C++ ?
Anonymous
How to return a free-able empty string 1-) return (""); 2-) return (strdup("")); 3-) char *r =""; return (r); 4-) char *r; r = malloc(1); *r =0;       return (r);
Anonymous
Which options valid answer?
Anonymous
Anonymous
Why?
Anónimo
it looks like homework
Anónimo
read the pinned message
Anónimo
no worries
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, I set a buffer like this: char *line= malloc(size of(*line)*64); Then I tried to read a file, in which this was written: a1b2c3d4e5f while(fgets(line, sizeof(line), fp)) Problem is, fgets will always read 7 bytes and not more. As you can see, I gave the buffer 64 char of space, so this bugs me. Why is this happening? It's like it encounters a \n after the seventh byte read
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Well since line is a char *, *line should be a char, therefore I'm allocating memory for 64 chars, or am I wrong?
klimi
Well since line is a char *, *line should be a char, therefore I'm allocating memory for 64 chars, or am I wrong?
The place where the pointer is pointing is at least 64 bytes/chars but the problem is that you are asking sizeof(char*) which is 8
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Ok now I understand, yep I really screwed up on that one ahaha, thank you very much for your support! Line was supposed to be declared like char line[64], therefore I wrote the fgets that way and never realized I had to change it. Thank you very much!!
Nomid Íkorni-Sciurus
Hello I'm using conan (CMakeToolchain, cmake, cmake_find_package_multi) and I'm trying to link SDL2 to my application. find_package(SDL2 REQUIRED CONFIG) add_executable(RVR ${DIR_SRC}/rvr.c ) target_link_libraries(RVR PUBLIC SDL2) This seems fine but when I try to build it, MSBuild just fails like this: LINK : fatal error LNK1104: cannot open file 'SDL2.lib' Any ideas?
Nomid Íkorni-Sciurus
Solved it. I didn't specify lib, *.lib* -> ./bin in my conanfile imports
.....
H
M
Hello guys I want to Find the minimum number of coins that make a given value Using (dynamic programming with memoization) Here is the code 👇🏻 in a bottom-up manner. Who can help me writing the code in a top-down manner (memoization)🥲?
M
// A Dynamic Programming based C++ program to find minimum // of coins to make a given change V #include <bits/stdc++.h> using namespace std; // m is size of coins array (number of different coins) int minCoins(int coins[], int m, int V) { // table[i] will be storing the minimum number of coins // required for i value. So table[V] will have result int table[V + 1]; // Base case (If given value V is 0) table[0] = 0; // Initialize all table values as Infinite for (int i = 1; i <= V; i++) table[i] = INT_MAX; // Compute minimum coins required for all // values from 1 to V for (int i = 1; i <= V; i++) { // Go through all coins smaller than i for (int j = 0; j < m; j++) if (coins[j] <= i) { int sub_res = table[i - coins[j]]; if (sub_res != INT_MAX && sub_res + 1 < table[i]) table[i] = sub_res + 1; } } if (table[V] == INT_MAX) return -1; return table[V]; } // Driver program to test above function int main() { int coins[] = { 9, 6, 5, 1 }; int m = sizeof(coins) / sizeof(coins[0]); int V = 11; cout << "Minimum coins required is " << minCoins(coins, m, V); return 0; }
Nomid Íkorni-Sciurus
Nomid Íkorni-Sciurus
https://docs.conan.io/en/latest/reference/conanfile_txt.html?highlight=dylib