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

Confusing behavior of sizeof with chars [duplicate]

TL;DR – sizeof works on the type of the operand. sizeof(ch) == sizeof (char)——————-(1) sizeof(‘a’) == sizeof(int) ——————–(2) sizeof (‘a’+ ‘b’ + ‘c’) == sizeof(int) —(3) sizeof (“a”) == sizeof (char [2]) ———-(4) Let’s see each case now. ch is defined to be of char type, so , pretty straightforward. In C, sizeof(‘a’) is the … Read more

Sizeof vs Strlen

sizeof and strlen() do different things. In this case, your declaration char string[] = “october”; is the same as char string[8] = “october”; so the compiler can tell that the size of string is 8. It does this at compilation time. However, strlen() counts the number of characters in the string at run time. So, … Read more

sizeof a union in C/C++

A union always takes up as much space as the largest member. It doesn’t matter what is currently in use. union { short x; int y; long long z; } An instance of the above union will always take at least a long long for storage. Side note: As noted by Stefano, the actual space … Read more

Is C++ allowed to increase the derived class size if there’re no new member variables compared to the base class?

From 5.3.2 [expr.sizeof] When applied to a class, the result [of sizeof] is the number of bytes in an object of that class including any padding required for placing objects of that type in an array. The size of a most derived class shall be greater than zero (1.8). From 1.8 [intro.object] Unless it is … Read more

Maximum size of size_t

The standard says that SIZE_MAX must be at least 65535. It specifies no upper bound, and gcc’s implementation is perfectly valid. Quoting the reference you cited (emphasis added): Its implementation-defined value shall be equal to or greater in magnitude (absolute value) than the corresponding value given below, with the same sign.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)