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

Parameters declared restrict and compiler warnings

Neither gcc 5 nor clang 3.6 give warnings where the constraints of the restrict qualifier are violated, even when called with -Wall. Consider the following code fragment: extern void f(char *restrict p, char *restrict q); void g(char *p) { …
jch
  • 5,382
  • 22
  • 41
16
votes
7 answers

C - Implementing fast push of many elements to the end of array

I have a simple struct to hold an array: struct array_of_a_type { size_t allocated_size; size_t elements; /* 1-index based */ a_type *array; }; I want to write a simple function, something like this: bool…
Michas
  • 8,534
  • 6
  • 38
  • 62
16
votes
2 answers

How to define extern variable along with declaration?

Wiki says: The extern keyword means "declare without defining". In other words, it is a way to explicitly declare a variable, or to force a declaration without a definition. It is also possible to explicitly define a variable, i.e. to force a…
haccks
  • 104,019
  • 25
  • 176
  • 264
16
votes
3 answers

NULL function pointers

What is the behavior of calling a null function pointer? void (*pFunc)(void) = NULL; pFunc(); Why is it advisable to initialize yet unused function pointers to NULL?
Vorac
  • 8,726
  • 11
  • 58
  • 101
16
votes
6 answers

What can human beings make out of the restrict qualifier?

If I got the C99 restrict keyword right, qualifying a pointer with it is a promise made that the data it references won't be modified behind the compiler's back through aliasing. By contrast, the way I understand the const qualifier is as…
Jérémie Koenig
  • 1,198
  • 6
  • 11
16
votes
7 answers

Is it possible to instruct C to not zero-initialize global arrays?

I'm writing an embedded application and almost all of my RAM is used by global byte-arrays. When my firmware boots it starts by overwriting the whole BSS section in RAM with zeroes, which is completely unnecessary in my case. Is there some way I can…
Maestro
  • 9,046
  • 15
  • 83
  • 116
16
votes
3 answers

"int" really required to be at least as large as "short" in C?

I've read a couple of times in different sources (e.g. Wikipedia: http://en.wikipedia.org/wiki/C_variable_types_and_declarations#Size), that in C, a long long is not smaller than a long, which is not smaller than an int, which is not smaller than a…
Hermann Speiche
  • 894
  • 1
  • 9
  • 16
16
votes
4 answers

Is returning va_list safe in C?

I'd like to write a function that has return type of va_list. example: va_list MyFunc(va_list args); is this safe and portable?
Hayri Uğur Koltuk
  • 2,970
  • 4
  • 31
  • 60
15
votes
1 answer

Is there a practical use for a `volatile restrict` pointer?

I can see practical use for a const volatile qualified variable, like const volatile uint64_t seconds_since_1970; if an underlying hardware mechanism updates the value every second, but the variable is not writable in the (possibly embedded)…
Johan Bezem
  • 2,582
  • 1
  • 20
  • 47
15
votes
3 answers

What C program behaves differently in run-time when compiled with C89 and C99?

I found the following snippet (I think in Wikipedia) that creates a different run-time when C++ comments are recognized than when not: int a = 4 //* This is a comment, but where does it end? */ 2 ; But until now that's been the only one (variants…
Johan Bezem
  • 2,582
  • 1
  • 20
  • 47
15
votes
10 answers

Define a function before main?

Are function declarations/prototypes necessary in C99 ? I am currently defining my functions in a header file and #include-ING it in the main file. Is this OK in C99 ? Why do most programmers declare/prototype the function before main() and define…
Neeladri Vishweswaran
  • 1,695
  • 5
  • 22
  • 40
14
votes
2 answers

How do I have a comma inside braces inside a macro argument when parentheses cause a syntax error?

I've defined a few macros that make it simpler to define an array of structures, but I can't find a way to use them without generating errors. Here are the macros (and a few example structures to demonstrate why the macros might be used (the actual…
icktoofay
  • 126,289
  • 21
  • 250
  • 231
14
votes
3 answers

In C, if B is volatile, should the expression (void)(B = 1) read B

I work on compilers for a couple of embedded platforms. A user has recently complained about the following behaviour from one of our compilers. Given code like this: extern volatile int MY_REGISTER; void Test(void) { (void) (MY_REGISTER =…
Ned
  • 2,142
  • 17
  • 24
14
votes
2 answers

Are all of the features of C99 also in C++?

This page lists 53 features that were new in C99 (i.e they are in C99 but not C89). Are all of these features also in C++? Even C++98? If not, which of the features are in C++ and which are not?
user200783
  • 13,722
  • 12
  • 69
  • 135
14
votes
3 answers

better understanding type promotion of variadic parameters in c

When a variable argument function is called in c the integer parameters are promoted to int and floating point parameters are promoted to double Since the prototype doesn’t specify types for optional arguments, in a call to a variadic function the…
mastupristi
  • 1,240
  • 1
  • 13
  • 29