c99

Why can't gcc find the random() interface when -std=c99 is set?

时光怂恿深爱的人放手 提交于 2019-11-28 23:15:20
I do "#include <stdlib.h>" at the top of the source. Example compilation: /usr/bin/colorgcc -std=c99 -fgnu89-inline -g -Wall -I/usr/include -I./ -I../ -I../../ -I../../../ -I../../../../ -O3 -o f8 f8.c In file included from f8.c:7: ctype-cmp.c: In function ‘randomized’: ctype-cmp.c:48: warning: implicit declaration of function ‘random’ ctype-cmp.c: In function ‘main’: ctype-cmp.c:153: warning: implicit declaration of function ‘srandom’ ais@xcalibur:t$ When I turn off -std=c99, the function isfinite() can not be found. So I do want to use -std=c99 for this and other reasons. Is there some trick

How to compile for a freestanding environment with GCC?

荒凉一梦 提交于 2019-11-28 23:10:19
The code I'm working on is supposed to be possible to build for both hosted and freestanding environments, providing private implementations for some stdlib functions for the latter case. Can I reliably test this with just GCC on a normal workstation/build server? Compile for freestanding environment with GCC The "-ffreestanding" option looked promising, but it seems that it "only" disables built-ins and sets the STDC_HOSTED macro properly, it still provides all system headers. The option "-nostdinc" is too restrictive; I still want to use the headers required for a freestanding implementation

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 21:41:40
问题 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. 回答1: I tend to do something like this: struct foo_ops { void (*blah)(struct foo *, ...); void (*plugh)(struct foo *, ...); }; struct foo { struct foo_ops *ops; /* data fields for foo go here */ }; With these structure definitions, the code implementing foo looks something like this: static void plugh(struct foo *, ...) { ...

How to compile a C project in C99 mode?

只愿长相守 提交于 2019-11-28 21:15:31
I got the following error message while compiling the C code: error: 'for' loop initial declarations are only allowed in C99 mode note: use option -std=c99 or -std=gnu99 to compile your code What does it mean? How to fix it? Blorgbeard You have done this: for (int i=0;i<10;i++) { And you need to change it to this: int i; for (i=0;i<10;i++) { Or, as the error says, use option -std=c99 or -std=gnu99 to compile your code. Update copied from Ryan Fox's answer : gcc -std=c99 foo.c -o foo Or, if you're using a standard makefile, add it to the CFLAGS variable. luser droog You'll still need C99 if you

Is there a #define for C99?

六眼飞鱼酱① 提交于 2019-11-28 20:25:26
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 Khelben There is not an specific #define value. Just check __STDC_VERSION__ and define it yourself! ;-) #if __STDC_VERSION__ >= 199901L /* C99 code */ #define C99 #else /* Not C99 code */ #endif #ifdef C99 /*My code in C99 format*/ #else /*My code in C99 format*/ #endif EDIT: A more general snippet, from here . I've just changed the defined names, just in case you'll use them a lot on the code: #if defined(__STDC__) # define C89 # if defined(__STDC

Implicit declaration of function - C99

安稳与你 提交于 2019-11-28 19:09:52
I am currently using Xcode 4, and in my .pch file I have this macro: #define localize(s) NSLocalizedString((s), nil) . When I try to use this macro in some .m file, I receive this warning: Implicit declaration of function 'localize' is invalid in C99 . This code compiles without a problem, but how can I fix this so I don't get a warning? I had this problem when I did a global replace of NSLog with DLog. I foolishly included the #define DLog(...) NSLog(... statements, so I ended up with #define DLog(...) DLog(... which caused the warnings, and a linker error. Implicit function declarations are

How universally is C99 supported?

 ̄綄美尐妖づ 提交于 2019-11-28 17:46:06
How universally is the C99 standard supported in today's compilers? I understand that not even GCC fully supports it. Is this right? Which features of C99 are supported more than others, i.e. which can I use to be quite sure that most compilers will understand me? If you want to write portable C code, then I'd suggest you to write in C89 (old ANSI C standard). This standard is supported by most compilers. The Intel C Compiler has very good C99 support and it produces fast binaries. (Thanks 0x69 !) MSVC supports some new features and Microsoft plan to broaden support in future versions. GCC

printf/fprintf maximum size according to c99

こ雲淡風輕ζ 提交于 2019-11-28 13:54:21
The C99 standard says: The number of characters that can be produced by any single conversion shall be at least 4095 Does it mean that the maximum size is 4095 if yes why its says "at least"? You've found one of the more annoying aspects of the C language specifications. They don't usually say what a maximum is. Instead, they'll usually say what the smallest allowed value for a maximum is. They recognized that different hardware / compiler / linker environments have different restrictions, so they left most of the limits up to the individual tool authors. However, they wanted to provide some

C99 - why are false and true defined as 0 and 1 and not as ((bool)0) and ((bool)1)?

亡梦爱人 提交于 2019-11-28 13:49:04
Just stumbled across an assert, that failed, as it compared false to the returntype of a function, as the function itself returned a bool and the assert checked not only the value, but also the type of the returnvalue to match the one of false, to guarantee, that a bool is returned. Now the problem is, that C99 defines bool as _Bool and _Bool is even not necessarily same size as int (in fact, in my experience, on most platforms in nowadays it is often same size as unsigned char), not to talk about being same type (which is actually impossible, as _Bool is a builtin type of the language in C99)

Enumeration object set to a value not equal to any of its respective enumeration constants

拜拜、爱过 提交于 2019-11-28 13:39:42
What value does an enumeration object have if it is set to a value not equal to any of its respective enumeration constants? Consider the following code: enum foobar{ FOO = 1, BAR = 5 }; enum foobar baz = 5; enum foobar qux = 42; The variable baz is set to the integer value 5 , while the variable qux is set to the integer value 42 . I suspect the variable baz will hold the value BAR , but I'm unsure about the variable qux . No enumeration constant was assigned the value 42 , so what happens when an enum foobar variable is set to such a value? Is the C99 standard explicit about the outcome? The