c99

subexpressions evaluation order

I've looked at SO/IEC 9899:201x under J.1 Unspecified behavior: "The order in which subexpressions are evaluated and the order in which side effects take place, except as specified for the function-call (), &&, ||, ?:, and comma operators (6.5)." Does this means that in func1() + func2(); func2() may be preformed before func1(), o...

C - the most useful user-made C-macros (in GCC, also C99) ?

What C-macros is in your opinion is the most useful? I have found the following one, which I use to do vector arithmetics in C: #define v3_op_v3(x, op, y, z) {z[0]=x[0] op y[0]; \ z[1]=x[1] op y[1]; \ z[2]=x[2] op y[2];} It works like that: v3_op_v3(vectorA, +, vectorB, ve...

Can inline function bodies in C reference entities declared later

Lets say i have two inline functions in my header file: inline int foo() { return bar()+2; } inline int bar() { return 3; } can i assume that a C99 compiler will inline "foo" even if 'bar' is declared later? Assuming that no other internal rule like function body to large is triggered. Are implementations of c compilers doing this (p...

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? ...

Is it possible to iterate over arguments in variadic macros ?

Hi, I was wondering if it is possible to iterate over arguments passed to a variadic macro in C99 or using any GCC extensions ? For e.g. is it possible to write a generic macro that takes a structure and its fields passed as arguments and prints offset of each field within the structure ? Something like this: struct a { int a; ...

C99: Can I declare variables in the beginning of a block in a 'for'?

Is the following code legal according to C99? ... for(....) { int x = 4; ... } ... You can assume that before line 3 the variable x was never declared. C99 (PDF) Until now I have only found the following, but I dont think that this is enough: A block allows a set of declarations and statements to be grouped into one syntactic unit...

Is it possible (legal) to assign an anonymous union in a compound literal?

I have a struct: typedef struct _n { int type; union { char *s; int i; }; } n; When I try to assign a compound literal, like: node n1 = {1, 0}; node n2 = {2, "test"}; gcc gives me some warnings such as: warning: initialization makes pointer from integer without a cast warning: initialization from incomp...

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 which ones were not widely supported or even considered harmful. I know we could just ch...

Visual Studio 2008 Restrict to ANSI C

I want to restrict microsoft visual studio so that it can only run "C99" (ANSI C) code. Can any one give me some guideline? ...

Looping a statically allocated array, outside of c99 mode?

This is in reference to a solution posted on: http://stackoverflow.com/questions/1969588/looping-a-fixed-size-array-without-defining-its-size-in-c Here's my sample code: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { static const char *foo[] = { "this is a test", "hello world", ...

How is the bsearch() function in the standard C library implemented?

Does anyone know how the standard binary search function is implemented? This is the prototype. void * bsearch (const void*, const void*, size_t, size_t, int (*) (const void *, const void *) ); I'm really curious about how they used void pointers. ...

Literal string initializer for a character array

Hi, In the following rules for the case when array decays to pointer: An lvalue [see question 2.5] of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to its first element; the type of the resultant pointer is pointer-to-T. (The exceptions are when the array is the operand of a sizeo...

What are the most useful new features in C99?

C99 has been around for over 10 years, but support for it has been slow coming, so most developers have stuck with C89. Even today, I'm sometimes mildly surprised when I come across C99 features in C code. Now that most major compilers support C99 (MSVC being a notable exception, and some embedded compilers also lagging behind), I feel ...

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 ...

compiling with c89 and c99 does gcc 4.4.2 default to c99?

Hello, I am using gcc 4.4.2 on linux I am just wondering does gcc automatically default to compiling with c99 as its the latest standard? How can I specify if I want to compile with c89 or c99? Many thanks for any advice, ...

Is it correct C99 that you don't need to specify arguments in function pointer declarations in structs?

I have written the following C99 code and was wondering about the struct declaration. In it i declare two function pointers which ultimately point to the two push/pop methods in the main code. In the function pointer declarations i've ommited the arguments and the program compiles ok. Is this correct? I'm sure i've read that the argument...

Linkage in C: does GCC follow the C99 spec, or do I not understand the spec?

I'm trying to understand the exact behavior of storage class specifiers in C99, and some GCC behavior seems not to follow the spec, unless I misunderstand the spec. From 6.2.2 (2): Within one translation unit, each declaration of an identifier with internal linkage denotes the same object or function. However, I tested GCC (powerp...

Setting std=c99 flag in GCC

I was wondering if there were any files in which I could set the -std=c99 flag, so that I would not have to set it for every compilation. I am using GCC 4.4 on Ubuntu. ...

sizeof(void*) and sizeof(function_type_ptr*) equality

sizeof(void*) and sizeof(function_type_ptr*) equality Must sizeof(void*) and sizeof(function_type_ptr*) be equal? Is it required by C (C90, C99) standard? function_type_ptr is pointer to function. This question is about standard requirements, not your own opinion. Please, give links, section numbers and quotations from standards ...

Are there machines, where sizeof(char) != 1 ?

Are there machines (or compilers), where sizeof(char) != 1 ? Does C99 standard says that sizeof(char) on standard compliance implementation MUST be exactly 1? If it does, please, give me section number and citation. Upd: If I have a machine (CPU), which can't address bytes (minimal read is 4 bytes, aligned), but only 4-s of bytes (uint...