↧
Comment by Alex Lop. on Passing structure to parameter of type `const struct`...
Note that memcpy (bear->data, data, n); doesn't change the pointer bear->data but only the content to which it points. The prototype of memcpy guaranties it since the first operant is a pointer...
View ArticleComment by Alex Lop. on memcpy and string literal. does it check and consider...
@pmg why not? It will do exactly what it suppose to do. Was your account hacked? strncpy was not designed to work with strings???
View ArticleComment by Alex Lop. on Why are const qualified variables accepted as...
Does this answer your question? Why "initializer element is not a constant" is... not working anymore?
View ArticleComment by Alex Lop. on No output produce after running the code. Blank and...
"otherwise, you would be getting a segmentation fault." - using uninitialized pointer would lead to undefined behavior. Segmentation fault is only one of the possibilities but anything can happen,...
View ArticleComment by Alex Lop. on Include functions from other cpp(hpp) file with main()
Looks like you need additional shared.cpp and shared.hpp files which will declare and define shared function to be used in (other) various compilation object.
View ArticleComment by Alex Lop. on C structure: fields copy order
@Jabberwocky yeah, most likely you are right... but maybe there is some trick that we are not aware of... "no such thing" is also a possible answer to this question but I would like it to be based on...
View ArticleComment by Alex Lop. on C11 - omitting potentially infinite loop by the compiler
@KamilCuk A synchronization operation on one or more memory locations is either an acquire operation, a release operation, both an acquire and release operation, or a consume operation. - I couldn't...
View ArticleComment by Alex Lop. on Merge two bitmask with conflict resolving, with some...
Can you explain how you combine target from a and b? I am not sure I could follow your explanation.
View ArticleComment by Alex Lop. on Transfer from one array to another
what did you try to do so far?
View ArticleComment by Alex Lop. on Find the vulnerability in the C program
When and how does this code run? Can the attacker manipulate (change) the value to which name is pointing asynchronously?
View ArticleComment by Alex Lop. on c while turning void type to string getting weird...
You realize that currently word1 and word2 get a pointer to pointer of type void, right?
View ArticleAnswer by Alex Lop. for Check that all bits are set except the Least...
The code you wrote won't check what you expectif ((myBitfield & 0xFE) == 1) // 0xFE = 0b11111110{/*yes all bits except the Least Significant is set*/}More than that, the code inside the if block...
View ArticleAnswer by Alex Lop. for Compiler optimization of strcmp I don't understand,...
The compiler inlined strcmp against a known-length string using repe cmpsb which implements memcmp.It loads into register esi the address of the constant literal string "LETMEWIN\n". Note that the...
View ArticleAnswer by Alex Lop. for Comparing a bit to a boolean
You can create a mask based on doSet value:#define AMAZING_FLAG_IDX 1#define AMAZING_FLAG (1u << AMAZING_FLAG_IDX)...uint16_t set_mask = doSet << AMAZING_FLAG_IDX;Now your check can look...
View ArticleAnswer by Alex Lop. for Can someone explain to me why my factorial recursion...
factorial(i) = (factorial(i - 1) * i);This line is invalid in terms of C standard. It is related to the lvalue and rvalue definition.lvalue - is an expression referring to an object.The name 'lvalue'...
View ArticleAnswer by Alex Lop. for How can I get GCC to optimize this bit-shifting...
In addition to Booboo's answer, you can try the following which answers your questionHow can I get GCC to optimize this into a move?Just cast each shifted bit-field expression to unsigned shortunsigned...
View ArticleAnswer by Alex Lop. for How to link two global variables to same address...
This doesn't directly answers your question but I would suggest defining a geter function in provider.h:const int *getConfigProvider(void);and in provider.cconst int *getConfigProvider(void){ static...
View ArticleAnswer by Alex Lop. for How to split string in c?
str_1 and str_2 are arrays of char and the way you fill in the data is fine. But when you are using puts() method, you have to mark the end of the string by '\0' character as described in this link...
View ArticleAnswer by Alex Lop. for Program to print all the bits of one byte union...
Maybe the point of this task is to use arithmetic operations instead of the bitwise ones?Here is an example:void printByteBits(unsigned char num){ const static int div[8] = {1, 2, 4, 8, 16, 32, 64,...
View ArticleAnswer by Alex Lop. for Why is /=2 different from >>=1 for signed integers,...
Dividing a negative integer by 2 is not the same as shifting it to the right by 1.For example -7 / 2 = -3With shifts:11111001b >> 1 = 11111100b which is -4Thus the compiler has to take care of...
View Article
More Pages to Explore .....