Questions tagged [c99]

This tag is for questions regarding the International Standard ISO 9899:1999, aka "C99", with technical corrigenda, and for questions about code written in C99 (as opposed to K&R C, C89 or later C Standard revisions like the 2011 revision C11).

This tag is for questions regarding the International Standard ISO 9899:1999 , aka "C99", with technical corrigenda, and for questions about code written in C99 (as opposed to K&R C, C89 or later C Standard revisions like the 2011 revision C11).

Always use the tag for all your C questions, then complement it with the tags for questions that are specific to this version of the standard.

1900 questions
24
votes
3 answers

What ABI, if any, restricts the size of [u]intmax_t?

Starting with the 1999 edition, the ISO C standard defines a standard header which defines, among other things, the typedefs intmax_t and uintmax_t. These designate, respectively, "a (signed|unsigned) integer type capable of representing…
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
24
votes
7 answers

c99 goto past initialization

While debugging a crash, I came across this issue in some code: int func() { char *p1 = malloc(...); if (p1 == NULL) goto err_exit; char *p2 = malloc(...); if (p2 == NULL) goto err_exit; ... err_exit: …
R Samuel Klatchko
  • 74,869
  • 16
  • 134
  • 187
24
votes
2 answers

error: unknown conversion type character 'l' in format - scanning long long

I'm trying to get long long from the console using standard IO function scanf. I started with %lld: scanf("%lld", &rule); That throws: error: unknown conversion type character 'l' in format [-Werror=format=] I've found more workarounds, but they…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
24
votes
3 answers

Variable length array in the middle of struct - why this C code is valid for gcc

There is some strange code using VLA (Variable Length Arrays) which is treated as Valid C (C99, C11) by gcc 4.6: $ cat a.c int main(int argc,char**argv) { struct args_t{ int a; int params[argc]; // << Wat? …
osgx
  • 90,338
  • 53
  • 357
  • 513
23
votes
5 answers

Is it always safe to convert an integer value to void* and back again in POSIX?

This question is almost a duplicate of some others I've found, but this specifically concerns POSIX, and a very common example in pthreads that I've encountered several times. I'm mostly concerned with the current state of affairs (i.e., C99 and…
Quantumboredom
  • 1,426
  • 11
  • 19
23
votes
7 answers

Return value range of the main function

What does standard say about main return values range? Say only up to 255? Because int main(void){ return 256; } echo $? ; # out 0
Nyan
  • 2,360
  • 3
  • 25
  • 38
23
votes
2 answers

Conventions to write simple additions of hexadecimal and decimal numbers

Even though an oldtimer, I fear I do not (anymore) have a complete grasp of parsing of constants in C. The second of the following 1-liners fails to compile: int main( void ) { return (0xe +2); } int main( void ) { return (0xe+2); } $ gcc -s…
Baard
  • 809
  • 10
  • 26
23
votes
2 answers

Is there a #define for C99?

I want to do something in C99 one way, otherwise to perform it another way. What is the #define to check for? #ifdef C99 ... #else ... #endif
klynch
  • 1,076
  • 2
  • 9
  • 15
23
votes
1 answer

Type punning with void * without breaking the strict aliasing rule in C99

I recently came across the strict aliasing rule, but I'm having trouble understanding how to use void * to perform type punning without breaking the rule. I know this breaks the rule: int x = 0xDEADBEEF; short *y = (short *)&x; *y = 42; int z =…
Vilhelm Gray
  • 11,516
  • 10
  • 61
  • 114
23
votes
5 answers

What is the header file for the uintptr_t type in modern C++?

I found that in C99 you should #include and that seems to work with my C++03 gcc compiler too, but is that the right header for modern C++, is it portable?
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
23
votes
1 answer

C99 printf formatters vs C++11 user-defined-literals

This code: #define __STDC_FORMAT_MACROS #include #include #include #include int main(int argc,char **argv) { uint64_t val=1234567890; printf("%"PRId64"\n",val); exit(0); } Works for C99, C++03,…
rubenvb
  • 74,642
  • 33
  • 187
  • 332
22
votes
4 answers

Are there reasons to avoid bit-field structure members?

I long knew there are bit-fields in C and occasionally I use them for defining densely packed structs: typedef struct Message_s { unsigned int flag : 1; unsigned int channel : 4; unsigned int signal : 11; } Message; When I read open…
wirrbel
  • 3,173
  • 3
  • 26
  • 49
22
votes
5 answers

Is it a good idea to use C99 VLA compared to malloc/free?

Is it a good idea to use C99 VLA? When is it appropriate to use VLA compared to malloc/free? (since VLA may blow up stack?)
Nyan
  • 2,360
  • 3
  • 25
  • 38
22
votes
3 answers

How to use make and compile as C99?

I'm trying to compile a linux kernel module using a Makefile: obj-m += main.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Which gives me: main.c:54:…
djTeller
  • 515
  • 2
  • 5
  • 14
22
votes
2 answers

Adding two floating-point numbers

I would like to compute the sum, rounded up, of two IEEE 754 binary64 numbers. To that end I wrote the C99 program below: #include #include #pragma STDC FENV_ACCESS ON int main(int c, char *v[]){ fesetround(FE_UPWARD); …
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281