Linked Questions

37 votes
10 answers
20k views

On a cross platform c/c++ project (Win32, Linux, OSX), I need to use the *printf functions to print some variables of type size_t. In some environments size_t's are 8 bytes and on others they are 4. ...
twk's user avatar
  • 17.4k
0 votes
0 answers
70 views

I read that the size of a struct is at least the sum of individual fields inside it, and it can be greater than that when using struct array for alignment. What is alignment, why does it add that so ...
Sahil Gautam's user avatar
721 votes
20 answers
54k views

C and C++ have many differences, and not all valid C code is valid C++ code. (By "valid" I mean standard code with defined behavior, i.e. not implementation-specific/undefined/etc.) Is there any ...
user541686's user avatar
  • 213k
549 votes
14 answers
468k views

I have a variable of type size_t, and I want to print it using printf(). What format specifier do I use to print it portably? In 32-bit machine, %u seems right. I compiled with g++ -g -W -Wall -...
Arun's user avatar
  • 20.6k
352 votes
21 answers
107k views

The following code receives seg fault on line 2: char *str = "string"; str[0] = 'z'; // could be also written as *str = 'z' printf("%s\n", str); While this works perfectly well: char str[] = "...
Markus's user avatar
  • 3,641
316 votes
11 answers
358k views

I was wondering if someone could explain to me what the #pragma pack preprocessor statement does, and more importantly, why one would want to use it. I checked out the MSDN page, which offered some ...
Cenoc's user avatar
  • 11.8k
161 votes
10 answers
163k views

I'm trying to print types like off_t and size_t. What is the correct placeholder for printf() that is portable? Or is there a completely different way to print those variables?
Georg Schölly's user avatar
112 votes
3 answers
68k views

I want to print out a variable of type size_t in C but it appears that size_t is aliased to different variable types on different architectures. For example, on one machine (64-bit) the following code ...
Ethan Heilman's user avatar
22 votes
4 answers
5k views

printf("%lu \n", sizeof(*"327")); I always thought that size of a pointer was 8 bytes on a 64 bit system but this call keeps returning 1. Can someone provide an explanation?
lordgabbith's user avatar
28 votes
2 answers
44k views

I am working with structs in c on linux. I started using bit fields and the "packed" attribute and I came across a wierd behavior: struct __attribute__((packed)) { int a:12; int b:32;...
Danny Cohen's user avatar
41 votes
2 answers
3k views

I ran the following program on my computer (64-bit Intel running Linux). #include <stdio.h> void test(int argc, char **argv) { printf("[test] Argc Pointer: %p\n", &argc); printf("[...
letmutx's user avatar
  • 1,416
12 votes
7 answers
2k views

Can you think of 'a program' which gives 'different outputs for a C and a C++ compilers' (yet gives consistent output under the same language)?
Aditya369's user avatar
  • 566
21 votes
3 answers
67k views

I am trying to compile the below on RHEL 5.6 , 64 bit, and i keep getting a warning "var.c:7: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’" Here is my ...
Jimm's user avatar
  • 8,625
21 votes
4 answers
27k views

By man I find printf("%*d", width, num); and printf("%2$*1$d", width, num); are equivalent. But IMO the second style should be the same as: printf("%*...
Je Rog's user avatar
  • 6,131
18 votes
7 answers
29k views

I have been advised to use the following options with GCC, as it helps to avoid a lot of common errors. It turns on a bunch of warnings and -Werror turns them into errors. gcc -pedantic -W -Wall -...
George's user avatar
  • 15.7k

15 30 50 per page
1
2 3 4 5 6