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
17
votes
2 answers

Bit-fields and sequence points

For an implementation that packs f0 and f1 into the same byte, is the program below defined? struct S0 { unsigned f0:4; signed f1:4; } l_62; int main (void) { (l_62.f0 = 0) + (l_62.f1 = 0); return 0; } I am interested…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
17
votes
3 answers

C: cast int to size_t

What is the proper way to convert/cast an int to a size_t in C99 on both 32bit and 64bit linux platforms? Example: int hash(void * key) { //... } int main (int argc, char * argv[]) { size_t size = 10; void * items[size]; //... …
Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
17
votes
4 answers

Compatibility of C89/C90, C99 and C11

I just read: C Wikipedia entry. As far as I know there are 3 different versions of C that are widely used: C89, C99 and C11. My question concerns the compatibility of source code of different versions. Suppose I am going to write a program (in C11…
Michael S
  • 466
  • 1
  • 4
  • 12
17
votes
2 answers

Is it legal and well defined behavior to use a union for conversion between two structs with a common initial sequence (see example)?

I have an API with a publicly facing struct A and an internal struct B and need to be able to convert a struct B into a struct A. Is the following code legal and well defined behavior in C99 (and VS 2010/C89) and C++03/C++11? If it is, please…
Coder
  • 441
  • 2
  • 17
17
votes
5 answers

Can "sizeof(arr[0])" lead to undefined behavior?

There is a well known pattern of figuring out array length: int arr[10]; size_t len = sizeof(arr) / sizeof(arr[0]); assert(len == 10); This pattern applies to static arrays and auto arrays of constant size. It also applies to variable length…
mrsmith
  • 291
  • 2
  • 8
17
votes
4 answers

struct bitfield max size (C99, C++)

What is maximal bit width for bit struct field? struct i { long long i:127;} Can I define a bit field inside struct, with size of bitfield up to 128 bit, or 256 bit, or larger? There are some extra-wide vector types, like sse2 (128-bit), avx1/avx2…
osgx
  • 90,338
  • 53
  • 357
  • 513
17
votes
2 answers

Using restrict with arrays?

Is there a way to tell a C99 compiler that the only way I am going to access given array is by using myarray[index] ? Say something like this: int heavy_calcualtions(float* restrict range1, float* restrict range2) { float __I promise I won't…
Piotr Lopusiewicz
  • 2,514
  • 2
  • 27
  • 38
17
votes
3 answers

GCC options to enforce Ansi C standard check?

What gcc options shall I use to enforce ANSI C (C99) warnings/errors? gcc (GCC) 3.4.2 (mingw-special) I'm using: gcc -pedantic -ansi -std=c99 is this correct?
AlfaTeK
  • 7,487
  • 14
  • 49
  • 90
17
votes
8 answers

Is C99 backward compatible with C89?

I'm used to old-style C and and have just recently started to explore c99 features. I've just one question: Will my program compile successfully if I use c99 in my program, the c99 flag with gcc and link it with prior c99 libraries? So, should I…
kar
  • 977
  • 10
  • 21
17
votes
2 answers

Will "&a+1 > &a" cause an undefined behaviour

Does c99/c++03 guarantee that &a+1 > &a is always true? for example, there's a (c-like) std::copy, and int a = 0 ; int b[9] ; std__copy(&a , &a+1 , b) ; Does this always work?
exprosic
  • 630
  • 5
  • 17
17
votes
1 answer

Understanding restrict qualifier by examples

The restrict keyword's behavior is defined in C99 by 6.7.3.1: Let D be a declaration of an ordinary identifier that provides a means of designating an object P as a restrict-qualified pointer to type T. If D appears inside a block and does not…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
17
votes
5 answers

Why weren't new (bit width specific) printf() format option strings adoped as part of C99?

While researching how to do cross-platform printf() format strings in C (that is, taking into account the number of bits I expect each integer argument to printf() should be) I ran across this section of the Wikipedia article on printf(). The…
mpontillo
  • 13,559
  • 7
  • 62
  • 90
16
votes
1 answer

Creating a DLL in GCC or Cygwin?

I need help to compile a script ("iterator.c") into a DLL. I can't use VS2010 since it does not support the features added to C in the C99 standard (I'm using "complex.h" but VB doesn't support it). I've been looking for a substitute but all I've…
Daniel Torramilans
  • 295
  • 2
  • 3
  • 8
16
votes
1 answer

Why are uintptr_t and intptr_t optional types in the C (and C++) standard?

With C99 (and later standards) standard requires certain types to be available in the header . For exact-width, e.g., int8_t, int16_t, etc..., they are optional and motivated in the standard why that is. But for the uintptr_t and intptr_t…
Bo R
  • 2,334
  • 1
  • 9
  • 17
16
votes
2 answers

Are there any differences between ANSI C and ISO C?

I understand that there is both an ANSI standard and an ISO standard for C. Are there any differences between these two standards? If so, what are they? And if there is not a difference then what's the point of having two standards?
Earlz
  • 62,085
  • 98
  • 303
  • 499