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
19
votes
3 answers

Declaring an array of negative length

What happens in C when you create an array of negative length? For instance: int n = -35; int testArray[n]; for(int i = 0; i < 10; i++) testArray[i]=i+1; This code will compile (and brings up no warnings with -Wall enabled), and it seems you…
jonmorgan
  • 2,570
  • 2
  • 22
  • 27
19
votes
2 answers

Valid programs in C89, but not in C99

Are there features / semantics introduced, or removed, in C99 which would make a well defined program written in C89 either invalid (i.e not compiling anymore, according to the C99 standard) compiling, but having different semantics. My findings…
Leandros
  • 16,805
  • 9
  • 69
  • 108
19
votes
4 answers

Why can't I "goto default;" or "goto case x;" within a switch selection structure?

Section 6.8.1 of C11 or C99, or section 3.6.1 of C89 all seem to indicate that default and case x (where x is some constant-expression) are examples of labeled statements, along-side identifier:-style labels that are suitable for use with goto. I'm…
autistic
  • 1
  • 3
  • 35
  • 80
19
votes
3 answers

Does C99 guarantee that arrays are contiguous?

Following an hot comment thread in another question, I came to debate of what is and what is not defined in C99 standard about C arrays. Basically when I define a 2D array like int a[5][5], does the standard C99 garantee or not that it will be a…
kriss
  • 23,497
  • 17
  • 97
  • 116
19
votes
1 answer

Why do some C standard headers begin with 'std' while others don't?

For example, in the new C11 standard there have been added stdalign.h and threads.h. Why not stdthreads.h or align.h? Is it to avoid collisions with existing libraries and system headers?
szx
  • 6,433
  • 6
  • 46
  • 67
19
votes
1 answer

Lifetime of temporary objects in C11 vs C99

I am trying to decipher a note that led to a change between C99 and C11. The change proposed in that note ended up in C11's 6.2.4:8, namely: A non-lvalue expression with structure or union type, where the structure or union contains a member…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
18
votes
4 answers

Why can't gcc find the random() interface when -std=c99 is set?

I do "#include " at the top of the source. Example compilation: /usr/bin/colorgcc -std=c99 -fgnu89-inline -g -Wall -I/usr/include -I./ -I../ -I../../ -I../../../ -I../../../../ -O3 -o f8 f8.c In file included from f8.c:7: ctype-cmp.c:…
Setjmp
  • 27,279
  • 27
  • 74
  • 92
18
votes
2 answers

Is there any option to switch between C99 and C11 C standards in Visual Studio?

I am new to Visual Studio Environment and I am using VS2017 Pro. I wanted to write simple program in C and compiled with both c99 and c11 standards. In Visual Studio, I could only find compiler switches for C++ standards only. How can we tell visual…
user9411335
18
votes
2 answers

Why are compound literals in C modifiable

One does usually associate 'unmodifiable' with the term literal char* str = "Hello World!"; *str = 'B'; // Bus Error! However when using compound literals, I quickly discovered they are completely modifiable (and looking at the generated machine…
hgiesel
  • 5,430
  • 2
  • 29
  • 56
18
votes
3 answers

Optimizing linear access to arrays with pre-fetching and cache in C

disclosure: I've tried similar question on programmers.stack, but that place is nowhere near activity stack is. Intro I tend to work with lots of large images. They also come in sequences of more than one and have to be processed and played back…
Keyframe
  • 1,390
  • 1
  • 14
  • 28
18
votes
6 answers

Free static checker for C99 code

I am looking for a free static checker for C99 code (including GCC extensions) with the ability to explicitly say "these preprocessor macros are always defined." I need that last part because I am compiling embedded code for a single target…
detly
  • 29,332
  • 18
  • 93
  • 152
18
votes
3 answers

How enable c99 mode in gcc with terminal

I want to activate c99 mode in gcc compiler to i read in other post in this forum that -std should be equal to -std=c99 but i don't know how to set it to this value using command line so please help.
user297904
  • 417
  • 1
  • 4
  • 12
18
votes
7 answers

What C99 features are considered harmful or unsupported

I usually write C code in C89, now some features of C99 (like intxx_t or __VA_ARGS__ or snprintf) are very useful, and can be even vital. Before I more my requirements from C89 to C99 I wanted to know which of C99 features were widely supported and…
Nicolas Goy
18
votes
5 answers

What is the equivalent Haskell type for C99 bool when using FFI?

I have a library which uses C99 bool data type and I would like to call it via FFI. What is the corresponding type for C99 bool in Haskell? In Foreign.C.types there are CInt, CShort etc, but no CBool. If there is no "correct" type for bool, what is…
Zouppen
  • 1,214
  • 11
  • 17
18
votes
4 answers

Kernel's "container_of" - any way to make it ISO conforming?

While looking at Linux kernel's implementation of doubly linked circular lists, I've found following macro: #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr -…
Tomas Pruzina
  • 8,397
  • 6
  • 26
  • 39