Skip to main content
-1 votes
3 answers
123 views

Given the following C struct: struct __attribute__((__packed__)) XIRControl { uint8_t command; char code[19]; uint16_t error; union codeData { struct rcvCommands { ...
Jon Anthony's user avatar
15 votes
4 answers
1k views

Unlike C array, std::array is allowed to have zero length. But the current implementations differ in how std::array<T,0> is implemented, in particular the sizes of the object are different. This ...
Fedor's user avatar
  • 24.7k
0 votes
3 answers
265 views

When the array type is a "void *", then it can be allocated by: void **void_array; void_array = malloc(sizeof(void*) * 1); But, if the array type is a struct Hello *, then what should be ...
stackbiz's user avatar
  • 1,914
3 votes
4 answers
324 views

Say, is sizeof(void*) the same as the size processor can atomically access per instruction? For example, 32-bit processor can read aligned 4 bytes atomically, 64-bit processor can read aligned 8 bytes ...
PkDrew's user avatar
  • 2,301
0 votes
1 answer
108 views

This does not answer my need. I do not want to generate an error, I want to adapt the behavior of the software depending on the condition. Example: #if ( sizeof(unsigned long) == 4 ) # define a 5 #...
virolino's user avatar
  • 2,331
1 vote
1 answer
221 views

I did a static_assert to make sure that a valid type was used. I don't know if I just should have checked if the type is void, or whether any type can have size zero (I think it can with [[...
Zebrafish's user avatar
  • 16.3k
3 votes
1 answer
134 views

I want to create a function like SizeOf() of C++ for powershell, but apparently Microsoft uses some strange algorithm/formula to determine the mebibytes. Example: If you create file with exactly 1.856....
EverGreen's user avatar
1 vote
4 answers
192 views

Consider this example where I add some extra \0 to a string. #include <stdio.h> #include <string.h> int main(int argc, char **argv){ char str1[] = "dog"; char str2[] = &...
Labeeb's user avatar
  • 117
0 votes
0 answers
57 views

I declared 2 arrays with the first one of size 6 and tried to concatenate the arrays using strcat(), then checked the number of elements in the array but the array size is still showing 6 and still it ...
N Rogith's user avatar
3 votes
2 answers
197 views

I've got a question regarding the sizeof() operator. Browsing Open Source projects written in C obviously, some developers tend to use the sizeof() operator in one place and on other places the ...
MaSc. H.'s user avatar
  • 133
-6 votes
1 answer
168 views

There is one huge struct in our code, and its being passed around everywhere as a value. I would like to be able to know the size(amount of memory in bytes, go will allocate for a variable of this ...
Nitin Kumar's user avatar
4 votes
5 answers
236 views

I have an array of color codes, the size of which is known at compile time. I want to declare another array of the same size. But the code below throws an error. I can, of course, declare the size ...
Mike's user avatar
  • 822
3 votes
1 answer
171 views

Suppose we have the source: #include <stdint.h> #include <stdio.h> struct foo { char b ; char a [ SIZE_MAX ] ; } ; int main ( void ) { const size_t z = sizeof ( struct foo ) ; ...
Ana Nimbus's user avatar
2 votes
0 answers
120 views

Does the C++ standard have anything to say about the size equality of the following? struct AB { int a; int b; } Or struct A { int a }; struct B : public A { int b; } Is sizeof(...
Boris's user avatar
  • 1,489
4 votes
6 answers
274 views

So my professor gave us the assignment to code a function that works exactly like strcmp() but without using any library functions. I came up with the following code but instead of returning 1 or -1 ...
Nebelmonster's user avatar

15 30 50 per page
1
2 3 4 5
145