c99

Does Microsoft visual studio 2010 support c99?

与世无争的帅哥 提交于 2019-11-27 05:16:45
I would like to know if Microsoft Visual Studio 2010 supports C99. If not, how can I use the standard types like intptr_t and uintptr_t ? David Grayson As far as I can tell, Visual Studio 2010 does not support C99. To use types from stdint.h, you will have to use a typedef. A cross-platform way to do this would be: #ifdef _WIN32 typedef signed short int16_t #else #include <stdint.h> #endif See also this this question: Visual Studio support for new C / C++ standards? Visual Studio 2010 does not support C99 syntax. stdint.h is a very common file in all C/C++ compilers, though, which does exist

c99 goto past initialization

喜你入骨 提交于 2019-11-27 04:30:29
While debugging a crash, I came across this issue in some code: int func() { char *p1 = malloc(...); if (p1 == NULL) goto err_exit; char *p2 = malloc(...); if (p2 == NULL) goto err_exit; ... err_exit: free(p2); free(p1); return -1; } The problem occurs when the first malloc fails. Because we jump across the initialization of p2 , it contains random data and the call to free(p2) can crash. I would expect/hope that this would be treated the same way as in C++ where the compiler does not allow a goto to jump across an initialization. My question: is jumping across an initialization allowed by the

Why was mixing declarations and code forbidden up until C99?

ぐ巨炮叔叔 提交于 2019-11-27 04:28:04
I have recently become a teaching assistant for a university course which primarily teaches C. The course standardized on C90, mostly due to widespread compiler support. One of the very confusing concepts to C newbies with previous Java experience is the rule that variable declarations and code may not be intermingled within a block (compound statement). This limitation was finally lifted with C99, but I wonder: does anybody know why it was there in the first place? Does it simplify variable scope analysis? Does it allow the programmer to specify at which points of program execution the stack

How to properly add hex escapes into a string-literal?

大城市里の小女人 提交于 2019-11-27 04:27:53
When you have string in C, you can add direct hex code inside. char str[] = "abcde"; // 'a', 'b', 'c', 'd', 'e', 0x00 char str2[] = "abc\x12\x34"; // 'a', 'b', 'c', 0x12, 0x34, 0x00 Both examples have 6 bytes in memory. Now the problem exists if you want to add value [a-fA-F0-9] after hex entry. //I want: 'a', 'b', 'c', 0x12, 'e', 0x00 //Error, hex is too big because last e is treated as part of hex thus becoming 0x12e char problem[] = "abc\x12e"; Possible solution is to replace after definition. //This will work, bad idea char solution[6] = "abcde"; solution[3] = 0x12; This can work, but it

Anonymous union within struct not in c99?

陌路散爱 提交于 2019-11-27 04:27:33
here is very simplified code of problem I have: enum node_type { t_int, t_double }; struct int_node { int value; }; struct double_node { double value; }; struct node { enum node_type type; union { struct int_node int_n; struct double_node double_n; }; }; int main(void) { struct int_node i; i.value = 10; struct node n; n.type = t_int; n. int_n = i; return 0; } And what I don't undestand is this: $ cc us.c $ cc -std=c99 us.c us.c:18:4: warning: declaration does not declare anything us.c: In function ‘main’: us.c:26:4: error: ‘struct node’ has no member named ‘int_n’ Using GCC without -std option

What are the incompatible differences between C(99) and C++(11)?

荒凉一梦 提交于 2019-11-27 04:12:11
问题 This question was triggered by replie(s) to a post by Herb Sutter where he explained MS's decision to not support/make a C99 compiler but just go with the C(99) features that are in the C++(11) standard anyway. One commenter replied: (...) C is important and deserves at least a little bit of attention. There is a LOT of existing code out there that is valid C but is not valid C++. That code is not likely to be rewritten (...) Since I only program in MS C++, I really don't know "pure" C that

In C99, is f()+g() undefined or merely unspecified?

女生的网名这么多〃 提交于 2019-11-27 04:09:48
I used to think that in C99, even if the side-effects of functions f and g interfered, and although the expression f() + g() does not contain a sequence point, f and g would contain some, so the behavior would be unspecified: either f() would be called before g(), or g() before f(). I am no longer so sure. What if the compiler inlines the functions (which the compiler may decide to do even if the functions are not declared inline ) and then reorders instructions? May one get a result different of the above two? In other words, is this undefined behavior? This is not because I intend to write

Declaring an array of negative length

半腔热情 提交于 2019-11-27 04:07:20
问题 What happens in C when you create an array of negative length? For instance: int n = -35; int testArray[n]; for(int i = 0; i < 10; i++) testArray[i]=i+1; This code will compile (and brings up no warnings with -Wall enabled), and it seems you can assign to testArray[0] without issue. Assigning past that gives either a segfault or illegal instruction error, and reading anything from the array says "Abort trap" (I'm not familiar with that one). I realize this is somewhat academic, and would

What is the definition of “arithmetic operation” in C99?

落爺英雄遲暮 提交于 2019-11-27 03:55:27
问题 In C99, the term arithmetic operation appears 16 times, but I don't see a definition for it. The term arithmetic operator only appears twice in the text (again without definition) but it does appear in the Index: arithmetic operators additive, 6.5.6, G.5.2 bitwise, 6.5.10, 6.5.11, 6.5.12 increment and decrement, 6.5.2.4, 6.5.3.1 multiplicative 6.5.5, G.5.1 shift, 6.5.7 unary, 6.5.3.3 Then we have + - | & (binary) ++ -- * (binary) / % << >> ~ as arithmetic operators, if the Index is considered

How to wrap printf() into a function or macro?

早过忘川 提交于 2019-11-27 03:45:34
This sounds a little like an interview question,but is actually a practical problem. I am working with an embedded platform, and have available only the equivalents of those functions: printf() snprintf() Furthermore, the printf() implementation (and signature) is likely to change in the near future, so calls to it have to reside in a separate module, in order to be easy to migrate later. Given those, can I wrap logging calls in some function or macro? The goal is that my source code calls THAT_MACRO("Number of bunnies: %d", numBunnies); in a thousand places, but calls to the above functions