c99

Variables defined and assigned at the same time

A coding style presentation that I attended lately in office advocated that variables should NOT be assigned (to a default value) when they are defined. Instead, they should be assigned a default value just before their use. So, something like int a = 0; should be frowned upon. Obviously, an example of 'int' is simplistic but th...

Volatile semantics in C99

I have an issue with some low level code I am writing, I need to use objects as volatile, but it is not necessarily so that I want the types to be declared as volatile (for reusability reasons). I can however define pointer to a qualified variant of a structure as detailed in the following segment. struct x { int bar; }; struct x foo...

C99 complex support with visual studio

I would like to use complex numbers as defined in C99, but I need to support compilers which do not support it (MS compilers come to mind). I don't need many functions, and implementing the needed functions on compilers without support is not too difficult. But I have a hard time implementing the 'type' itself. Ideally, I would like to ...

Where is <inttypes.h> in Visual Studio 2005?

I'd like to use the C99 header file inttypes.h in a Visual Studio project (I'd like to printf 64 bit numbers). However, this file does not seem to exist in my install. Is this just not part of VS2005? Are there any alternatives? ...

Dots in Variables? VC9 gives parsing errors when building beecrypt

Hi, I want to compile the beecrypt library under VS2008. But several of the below structures produce a syntax error (C2059 syntax error: '.'): const hashFunction md5 = { .name = "MD5", .paramsize = sizeof(md5Param), .blocksize = 64, .digestsize = 16, .reset = (hashFunctionReset) md5Reset, .update = (hashFunctionUpdate) md5Update, .diges...

What techniques/strategies do people use for building objects in C (not C++)?

I am especially interested in objects meant to be used from within C, as opposed to implementations of objects that form the core of interpreted languages such as python. ...

What's the proper use of printf to display pointers padded with 0s

In C, I'd like to use printf to display pointers, and so that they line up properly, I'd like to pad them with 0s. My guess was that the proper way to do this was: printf("%016p", ptr); This works, but this gcc complains with the following message: warning: '0' flag used with ‘%p’ gnu_printf format I've googled a bit for it, and the...

Can output routines that print to a FILE* be used to build a string in C?

I have a bad feeling that the answer to this question is "no", but I wanted to throw this out there in case anyone has any clever ideas. I have a set of output routines that take a complex data structure and print it in a textual format. They have prototypes like: void print_mystruct(struct mystruct *s, FILE *stream) I wrote it this...

How does one configure Eclipse to compile using -std=c99?

The question is in the title. Using GCC version 3.4.5 on Windows Vista and a recent version of the Eclipse C/C++ IDE (not sure what version exactly because it's hard to figure out which version is the one for the whole IDE, but I downloaded it two weeks ago so it can't be that old). ...

Is there a reason that C99 doesn't support function overloading?

Apparently (at least according to gcc -std=c99) C99 doesn't support function overloading. The reason for not supporting some new feature in C is usually backward compatibility, but in this case I can't think of a single case in which function overloading would break backward compatibility. What is the reasoning behind not including thi...

Exception libraries for C (not C++)

Hi - I am rolling my own exception library for C and would like good examples to examine. So far, I have been looking at David Hanson's: http://drhanson.net/work/ But I know I've seen other ones available in the past. Can you send me some additional pointers? Thanks, SetJmp ...

fileno, F_LOCK and F_ULOCK become undeclared and unavailable when I add std=c99 flag to gcc

I have these headers in a c code #include <stdio.h> #include <unistd.h> Everything compiled fine until I added -std=c99 flag to gcc command (to enable restrict). And this triggered the following errors. warning: implicit declaration of function fileno error: F_LOCK undeclared (first use in this function) error: (Each u...

What are the semantics of C99's "restrict" with regards to pointers to pointers?

I am doing lots of matrix arithmetic and would like to take advantage of C99's restrict pointer qualifier. I'd like to setup my matrices as pointers to pointers to allow for easy subscripting, like so: int **A = malloc (ncols * sizeof(int *)); A[0] = malloc (nrows * ncols * sizof(int)); for (int i=1; i < ncols; i++) { A[i] = A[0] +...

What's the C++ equivalent of UINT32_MAX?

In C99, I include stdint.h and that gives me UINT32_MAX as well as uint32_t. However, in C++ the UINT32_MAX gets defined out. I can define __STDC_LIMIT_MACROS before including stdint.h, but this doesn't work if someone is including my header after already including stdint.h themselves. So in C++, what's the standard way of finding out...

Tentative definitions in C99 and linking

Consider the C program composed of two files, f1.c: int x; f2.c: int x=2; My reading of paragraph 6.9.2 of the C99 standard is that this program should be rejected. In my interpretation of 6.9.2, variable x is tentatively defined in f1.c, but this tentative definition becomes an actual definition at the end of the translation unit...

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 compiler-enforced documentation that a given object won't be modified behind the back of a human be...

Does the C preprocessor strip comments or expand macros first?

Consider this (horrible, terrible, no good, very bad) code structure: #define foo(x) // commented out debugging code // Misformatted to not obscure the point if (a) foo(a); bar(a); I've seen two compilers' preprocessors generate different results on this code: if (a) bar(a); // and if (a) ; bar(a) Obviously, this is a bad thing ...

How to auto-sync Header in Visual Studio ?

Do you know if there is a build-in feature or free add-in for Microsoft Visual Studio 2008 that easily generates C-Headers and keeps them in sync with their .c counterparts? I have already looked at Visual Assist X, but I'm not really willing to pay money at the moment. ...

How to declare IEEE mathematical functions like 'ilogbf' in MSVC++6?

Hi, Could someone please help and tell me how to include IEEE mathematical functions in MSVC++6? I tried both and , but I still get these errors: - error C2065: 'ilogbf' : undeclared identifier - error C2065: 'scalbnf' : undeclared identifier thanks in advance for your help, mk ...

C99 backward compatibility

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 stick to old C89 or evolve? Thanks. ...