c99

MS VS 2008 and C99

烈酒焚心 提交于 2019-12-11 10:37:05
问题 I read with interest the post "How universally is C99 supported ?". One of the comments therein points that Microsoft doesn't support C99. But the comment symbol // works with VS 2008 and this symbol is in C99. I have two questions: To what extent VS 2008 support C99? Is it ok in the same code to mix C89 and C99 syntax together? So if I write my code in C89 and then place a comment //. This means that I have mixed-coding. So what does the compiler do in such a case? Check my code first with

What is wrong passing a 2D array to a respective pointer argument?

回眸只為那壹抹淺笑 提交于 2019-12-11 10:36:51
问题 I've been doing some matrix calculation in C for university the other day where I had a 5x5 matrix to begin with so I hard-coded it into the source. It was a 2D array of doubles like: /** * This is the probability-matrix for reaching from any profile * to another by randomly selecting a friend from the friendlist. */ static const double F[5][5] = { /* P , F , L , A , S */ /* Peter */ {0 , 0.5 , 0.5 , 0 , 0 }, /* Franz */ {1.0 , 0 , 0 , 0 , 0 }, /* Lisa */ {0 , 1/3.0, 0 , 1/3.0, 1/3.0}, /*

How to invoke “.so” file in xcode

自作多情 提交于 2019-12-11 07:06:37
问题 How to invoke(call) ".so" file in xcode? these ".so" files are all writen in standard C.(C99). Anyone help..... 回答1: Apple uses the file extension ".dylib" for dynamic libraries. They are very similar to ".so" shared-object libraries used in other Unix-like operating systems, and are a cousin to ".dll" dynamic link libraries on Windows. Most .so libraries are in ELF format (used by Linux and many other POSIX systems) whereas Mac libraries are in Mach-O format. So, they are most definitely

Behavior of fscanf when format doesn't match file contents

拈花ヽ惹草 提交于 2019-12-11 03:28:34
问题 If the contents of a file do not match the format string passed to fscanf , what happens on the next call to fscanf ? Suppose a file contains the following two lines: 9000 pig dog 4 5 2 A program tries to parse the opened file ( fp ) as such: int a = 1, b = 1, c = 1; int x = 1, y = 1, z = 1; fscanf(fp, "%d %d %d", &a, &b, &c); fscanf(fp, "%d %d %d", &x, &y, &z); I suspect that a would now hold 9000 while b and c continue to hold the value 1 -- but what happens to x , y , and z ? Does the C99

Suggestions for concise index handling in circular buffer

余生颓废 提交于 2019-12-11 03:18:26
问题 I've implemented a circular buffer, and I would like a concise means of updating the buffer pointer while properly handling the wrap-around. Assuming an array of size 10, my first response was something like: size_t ptr = 0; // do some work... p = ++p % 10; Static analysis, as well as gcc -Wall -Wextra , rightly slapped my wrist for unspecified behavior due to a sequence point violation. The obvious fix is something like: p++; p %= 10; However, I was looking for something more concise, (i.e.,

Set array size at runtime

有些话、适合烂在心里 提交于 2019-12-11 02:13:03
问题 I know how to create a structure array inside a function: typedef struct item { int test; }; void func (void) { int arraysize = 5; item ar[arraysize]; } But how do I to the same when the array is declared globally: typedef struct item { int test; }; item ar[]; void func (void) { int arraysize = 5; // What to here? } 回答1: May be you like this: typedef struct item { int test; }; item *arr; void func (void) { int arraysize = 5; arr = calloc(arraysize,sizeof(item)); // check if arr!=NULL :

Is it valid to use a C99-style designated initializer list to initialize the members of a bit field within a union in the following way?

天大地大妈咪最大 提交于 2019-12-11 01:35:19
问题 When I wrote a question regarding PC-Lint, I had made an assumption that the following initialization is valid in C99. @JoachimPileborg mentioned that it may not be and I haven't been able to find any information that provides a good example one way or another. I know that it compiles and behaves as I expect, I would just like to know for certain that it is proper C99 code. Is this a valid way to initialize the following union in C99? typedef union { struct { unsigned int a : 4; unsigned int

Does the C99 standard guaranteed the binary representation of unsigned int?

本小妞迷上赌 提交于 2019-12-10 21:54:19
问题 C99 (ISO/IEC 9899:1999) 6.2.6.2/1 Integer types The values of any padding bits are unspecified. 45) A valid (non-trap) object representation of a signed integer type where the sign bit is zero is a valid object representation of the corresponding unsigned type, and shall represent the same value. For any integer type, the object representation where all the bits are zero shall be a representation of the value zero in that type. In the C99 standard, an integer type where all the bits are zero

How does the compiler resolve the address of variable declared after a variable-length array?

核能气质少年 提交于 2019-12-10 21:12:06
问题 Suppose I have the following function, which makes use of a variable-length array: void func(int size) { int var1; int arr[size]; int var2; ... } How does the compiler determine the address of var2 ? The only way that I can think of is by placing arr after var1 and var2 . But in that case, what if there were several variable-length arrays? Placing all of them after the "normal" variables would only help resolving the address of the first one. My implicit assumption here is that all the local

Assert the allocation of a variable-length array

六眼飞鱼酱① 提交于 2019-12-10 21:05:47
问题 I apologize for the possible duplicate (have not been able to find an answer to that): Do we need to ensure that the allocation of a variable-length array has completed successfully? For example: void func(int size) { int arr[size]; if (arr == NULL) { // Exit with a failure } else { // Continue as planned } } It seems obvious that the answer is yes , but the syntax arr == NULL feels a bit unusual. Thanks UPDATE: I admit to the fact that I haven't made sure that the code above even compiles