Size of pid_t, uid_t, gid_t on Linux

#include <stdio.h> #include <sys/types.h> int main() { printf(“pid_t: %zu\n”, sizeof(pid_t)); printf(“uid_t: %zu\n”, sizeof(uid_t)); printf(“gid_t: %zu\n”, sizeof(gid_t)); } EDIT: Per popular request (and because, realistically, 99% of the people coming to this question are going to be running x86 or x86_64)… On an i686 and x86_64 (so, 32-bit and 64-bit) processor running Linux >= 3.0.0, the …

Read more

C sizeof a passed array [duplicate]

There is no magic solution. C is not a reflective language. Objects don’t automatically know what they are. But you have many choices: Obviously, add a parameter Wrap the call in a macro and automatically add a parameter Use a more complex object. Define a structure which contains the dynamic array and also the size …

Read more

What is guaranteed about the size of a function pointer?

From C99 spec, section 6.2.5, paragraph 27: A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. Similarly, pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements. All pointers to structure types shall have the same representation and …

Read more

sizeof() operator in if-statement

sizeof is not a function, it’s an operator. The parentheses are not part of the operator’s name. It’s failing because the value generated has the unsigned type size_t, which causes “the usual arithmetic conversions” in which -1 is converted to unsigned, in which case it’s a very large number. Basically you’re comparing 4 > 0xffffffffu, …

Read more