c99

Token pasting in C

自闭症网瘾萝莉.ら 提交于 2019-12-05 08:17:52
After reading about VA_NARG I tried to implement function overloading depending on number of arguments in C using macros. Now the problem is: void hello1(char *s) { ... } void hello2(char *s, char *t) { ... } // PP_NARG(...) macro returns number of arguments :ref to link above // does not work #define hello(...) hello ## PP_NARG(__VA_ARGS__) int main(void) { hello("hi"); // call hello1("hi"); hello("foo","bar"); // call hello2("foo","bar"); return 0; } I've read this from C-faq. But still could not get it to work... Jens Gustedt This is because of the evaluation rules for macros. You would

Are there float and double types with fixed sizes in C99?

泪湿孤枕 提交于 2019-12-05 08:03:58
C99 states integer types like uint32_t, int16_t etc, where it's easy to see the number of bits used. Good to know in for instance embedded programming. I have not found any similar types for floating point values. Is there a standard? If not, why? Kwariz I found the answer in Any guaranteed minimum sizes for types in C? Quoting Jed Smith (with corrected link to C99 standard): Yes, the values in float.h and limits.h are system dependent. You should never make assumptions about the width of a type, but the standard does lay down some minimums. See §6.2.5 and §5.2.4.2.1 in the C99 standard . For

Which gcc optimization flags should I use?

為{幸葍}努か 提交于 2019-12-05 06:49:05
问题 If I want to minimize the time my c programs run, what optimization flags should I use (I want to keep it standard too) Currently I'm using: -Wall -Wextra -pedantic -ansi -O3 Should I also use -std=c99 for example? And is there I specific order I should put those flags on my makefile? Does it make any difference? And also, is there any reason not to use all the optimization flags I can find? do they ever counter eachother or something like that? 回答1: I'd recommend compiling new code with -std

C preprocessor using the closing bracket of a parent macro

北战南征 提交于 2019-12-05 06:31:08
I have this code which works: #include <stdio.h> #define A(x) x B #define B(x) C(x, #define C(x,y) y x) int main( void ) { printf( A("1") ("2") "3" ); } It prints 132 (the point of the A macro is to swap the thing which follows its parameters in brackets with everything after that until another closing bracket) But if I use that within another macro: #define Z(x) x printf( Z( A("1") ("2") "3" ) ); I get the compile error "Unterminated function-like macro invocation". I realise that this happens because the compiler is trying to process the arguments of Z independently, but I need to use its

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

六眼飞鱼酱① 提交于 2019-12-05 06:14:28
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 this basic feature? SingleNegationElimination To understand why you aren't likely to see overloading in C, it might help to better learn how overloading is handled by C++. After compiling code, but before it is ready to run, the intermediate object code must be

Are there any implementations that support a negative zero, or reserve it as a trap representation?

纵然是瞬间 提交于 2019-12-05 06:08:40
问题 On most implementations of this day and age, a signed integer value that has a bit pattern of 1 for the sign bit and all 0 for the value bits tends to represent the lowest possible value for that signed integer type. However, as 6.2.6.2p2 states, that's not a requirement: Which of these applies is implementation-defined, as is whether the value with sign bit 1 and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones' complement), is a trap representation or

Compatibility of C89/C90, C99 and C11

本秂侑毒 提交于 2019-12-05 03:41:54
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 since it is the latest version) and import a library written in C89. Are these two versions going to work together properly when compiling all files according to the C11 specification? Question 1 : Are the newer versions of C i.e. C99, C11 supersets of older C versions? By superset I mean, that old code will compile without errors and the same

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

本秂侑毒 提交于 2019-12-05 03:39:27
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 support in major compilers / toolchains? MSVC: Intentionally not implemented unless it overlaps with C++ GCC: Most of the useful parts are in (and have been for awhile). Some missing features. clang: Claims full C99 support 来源: https://stackoverflow.com/questions

Forcing compiler to C99 standard

江枫思渺然 提交于 2019-12-05 02:57:12
I was coding on my project when I discovered that the anonymous structs I've been using for a while are actually only available in C11, not C99, the standard I want to code against. Given the following code: struct data { int a; struct { int b; int c; }; }; int main() { struct data d; d.a = 0; d.b = 1; d.c = 2; return 0; } This code should only compile in C11 (or if compiler extensions provide this feature and are enabled). So let's see the results on different compilers: clang 5 compiler: Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) Target: x86_64-apple-darwin13.1.0 Thread

What is an efficient way to convert a bignum type structure to a human readable string?

自作多情 提交于 2019-12-05 01:14:49
问题 I've got a bit of a problem. In order to grow in my knowledge of C, I've decided to try to implement a basic bigint library. The core of the bigint structure will be an array of 32 bit integers, chosen because they will fit in a register. This will allow me to do operations between digits that will overflow in a 64 bit integer (which will also fit in a register, as I'm on x86-64), and I can bitshift out each part of the result. I've implemented basic addition, and to test that it is working,