c99

getaddrinfo is not statically compiled

I have included the header netdb.h, where getaddrinfo is included, but gcc issues this warning: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking gcc -m32 -static -s -O2 -std=c99 -D_POSIX_C_SOURCE=200112L myprogram.c How can I statically comp...

How, exactly, does the double-stringize trick work?

At least some C preprocessors let you stringize the value of a macro, rather than its name, by passing it through one function-like macro to another that stringizes it: #define STR1(x) #x #define STR2(x) STR1(x) #define THE_ANSWER 42 #define THE_ANSWER_STR STR2(THE_ANSWER) /* "42" */ Example use cases here. This does work, at least i...

Variable Length Array

Hello, I would like to know how a variable length array is managed (what extra variables or data structures are kept on the stack in order to have variable length arrays). Thanks a lot. ...

What is the state of C99 support in major compilers / toolchains?

A response to a comment I made here made me stop and think: "I don't really know what the state of C99 support is." Wikipedia gives details for a few compilers, but I'm not familiar enough with C99 to know all the bits and pieces of the standard, so I'm looking for a gestalt overview answer to the question: What is the state of C99 sup...

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: free(p2); free(p1); return -1; } The problem occurs when the first malloc fails. B...

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 contiguous block of ints, can I cast it to (int *)a and be sure I will have a valid 1D array...

va_arg with pointers

I want to initialize a linked list with pointer arguments like so: /* * Initialize a linked list using variadic arguments * Returns the number of structures initialized */ int init_structures(struct structure *first, ...) { struct structure *s; unsigned int count = 0; va_list va; va_start(va, first); for (s = f...

Generating 2-dimensional vla ends in segmentation fault

Hi, further developing the code from yesterday (seg fault caused by malloc and sscanf in a function), I tried with the help of some tutorials I found on the net to generate a 2-dim vla. But I get a segmentation fault at (*data)[i][j]=atof(p);. The program is supposed to read a matrix out of a text file and load it into a 2d array (cols ...

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: warning: ISO C90 forbids mixed declarations and code I need to switch to C99. After...

How do I know whether c89 or c99 is applied by cl.exe?

I just came across this term in this post, how do I check which rule is actually used by my compiler? Or is it possible to specify a rule for cl.exe? ...

What does (int (*)[])var1 stand for?

Hi, I found this example code and I tried to google what int (*)[])var1 could stand for, but I got no usefull results. #include <unistd.h> #include <stdlib.h> int i(int n,int m,int var1[n][m]) { return var1[0][0]; } int example() { int *var1 = malloc(100); return i(10,10,(int (*)[])var1); } Normally I work with VLAs in...

Should I use C(99) booleans ? ( also c++ booleans in c++ ?)

I haven't done much c programming but when I do when I need a false I put 0 when I want true I put 1, (ex. while(1)), in other cases I use things like "while(ptr)" or "if(x)". Should I try using C99 booleans, should I recommend them to others if I'm helping people new to programming learn c basics(thinking of cs 1?? students)? I'm p...

C99 mixed declarations and code in open source projects?

Why is still C99 mixed declarations and code not used in open source C projects like the Linux kernel or GNOME? I really like mixed declarations and code since it makes the code more readable and prevents hard to see bugs by restricting the scope of the variables to the narrowest possible. This is recommended by Google for C++. For ex...

Are "Statement and Declarations in Expressions" specific to GNU C ?

Are Statement and Declarations in Expressions specific to GNU C ? Or this feature is also included in C99 standard ? ...

C99 faq and Variable Length Arrays

Is there C99 faq like c-faq? 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?) ...

Does C99 allow UCHAR_MAX > UINT_MAX

6.3.1.1 States The rank of a signed integer type shall be greater than the rank of any signed integer type with less precision. The rank of long long int shall be greater than the rank of long int, which shall be greater than the rank of int, which shall be greater than the rank of short int, which shall be greater than the rank of sig...

How to enforce C89-style variable declarations in gcc ?

I work on a code base which is mostly C with a little C++, and is mostly built with gcc but occasionally it needs to be built with MSVC. Microsoft's C compiler is still pretty much C89 with a few minor extensions, and it still doesn't support mixed code and variable definitions à la C++/C99. So I need to find a way to prevent developers ...

gcc - 2 versions, different treatment of inline functions

Recently I've come across a problem in my project. I normally compile it in gcc-4, but after trying to compile in gcc-3, I noticed a different treatment of inline functions. To illustrate this I've created a simple example: main.c: #include "header.h" #include <stdio.h> int main() { printf("f() %i\n", f()); return 0; } file....

C90 - C99: register struct

Hello is "register struct" legal? In terms of standards and (separated from standards) in Gcc? ...

Allocating char array using malloc

Hi recently I saw a lot of code on online(also on SO;) like: char *p = malloc( sizeof(char) * ( len + 1 ) ); Why sizeof(char) ? It's not necessary, isn't it? Or Is it just a matter of style? What advantages does it have? ...