c99

What does dot (.) mean in a struct initializer?

人盡茶涼 提交于 2019-11-26 14:12:24
static struct fuse_oprations hello_oper = { .getattr = hello_getattr, .readdir = hello_readdir, .open = hello_open, .read = hello_read, }; I don't understand this C syntax well. I can't even search because I don't know the syntax's name. What's that? This is a C99 feature that allows you to set specific fields of the struct by name in an initializer. Before this, the initializer needed to contain just the values, for all fields, in order -- which still works, of course. So for the following struct: struct demo_s { int first; int second; int third; }; ...you can use struct demo_s demo = { 1, 2,

Good introduction to <inttypes.h> [closed]

拥有回忆 提交于 2019-11-26 13:08:56
问题 I want to recommend the use of <inttypes.h> to someone doing printf with mixed 32/64 bit builds. I tried to Google an introduction or tutorial page with a few examples and usage guidelines, but I couldn\'t find one. Can someone recommend an introduction or tutorial for <inttypes.h> ? 回答1: Try http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/inttypes.h.html for a start. A better example of how to use the new portable formatting macros was found in avr-libc. I've included an example

Is there a GCC keyword to allow structure-reordering?

被刻印的时光 ゝ 提交于 2019-11-26 12:46:22
问题 I know why GCC doesn\'t re-order members of a structure by default, but I seldom write code that relies on the order of the structure, so is there some way I can flag my structures to be automaticly reordered? 回答1: Previous GCC versions have the -fipa-struct-reorg option to allow structure reordering in -fwhole-program + -combine mode. -fipa-struct-reorg Perform structure reorganization optimization, that change C-like structures layout in order to better utilize spatial locality. This

Why was mixing declarations and code forbidden up until C99?

帅比萌擦擦* 提交于 2019-11-26 12:44:23
问题 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

Why are there digraphs in C and C++?

筅森魡賤 提交于 2019-11-26 12:25:01
问题 I learned today that there are digraphs in C99 and C++. The following is a valid program: %:include <stdio.h> %:ifndef BUFSIZE %:define BUFSIZE 512 %:endif void copy(char d<::>, const char s<::>, int len) <% while (len-- >= 0) <% d<:len:> = s<:len:>; %> %> My question is: why do they exist? 回答1: Digraphs were created for programmers that didn't have a keyboard which supported the ISO 646 character set. http://en.wikipedia.org/wiki/C_trigraph 回答2: I believe that their existence can be traced

C variable declarations after function heading in definition [duplicate]

流过昼夜 提交于 2019-11-26 11:39:23
问题 This question already has answers here : What is this strange function definition syntax in C? [duplicate] (6 answers) Closed 5 years ago . When reading some FreeBSD source code (See: radix.h lines 158-173), I found variable declarations that followed the \"function heading\" in the definition. Is this valid in ISO C (C99)? when should this be done in production code instead of just declaring the variables within the \"function heading?\" Why is it being done here? I refer to the function

How to use compound literals to `fprintf()` multiple formatted numbers with arbitrary bases?

回眸只為那壹抹淺笑 提交于 2019-11-26 11:32:03
问题 I\'d like to convert multiple numbers into some representation and then use the flags, width and precision of *printf() specifiers. Preference would be to avoid global or static buffers. The key problem appears to be is how to provide a char[] for each of the converted numbers? fprintf(ostream, \"some_format\", foo(int_a, base_x), foo(int_b, base_y), ...); How to use C11 compound literals to solve this? How to use C99 (or later) compound literals to solve this? 回答1: C99 C11 introduced

Does Microsoft visual studio 2010 support c99?

拥有回忆 提交于 2019-11-26 11:29:50
问题 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 ? 回答1: 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? 回答2: Visual Studio 2010 does not

C, reading multiple numbers from single input line (scanf?)

自作多情 提交于 2019-11-26 11:23:45
问题 I have written an app in C which expects two lines at input. First input tells how big an array of int will be and the second input contains values separated by space. For example, the following input 5 1 2 3 4 99 should create an array containing {1,2,3,4,99} What is the fastest way to do so? My problem is to read multiple numbers without looping through the whole string checking if it\'s space or a number? Thanks. 回答1: int i, size; int *v; scanf("%d", &size); v = malloc(size * sizeof(int));

c99 goto past initialization

十年热恋 提交于 2019-11-26 11:13:15
问题 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