c99

Literal string initializer for a character array

房东的猫 提交于 2019-11-27 02:58:27
In the following rules for the case when array decays to pointer: An lvalue [see question 2.5] of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to its first element; the type of the resultant pointer is pointer-to-T. (The exceptions are when the array is the operand of a sizeof or & operator, or is a literal string initializer for a character array.) How to understand the case when the array is "literal string initializer for a character array"? Some example please. Thanks! Prasoon Saurav The three exceptions where an array does not decay into a

Creating a DLL in GCC or Cygwin?

戏子无情 提交于 2019-11-27 02:44:01
问题 I need help to compile a script ("iterator.c") into a DLL. I can't use VS2010 since it does not support the features added to C in the C99 standard (I'm using "complex.h" but VB doesn't support it). I've been looking for a substitute but all I've found is GCC which I don't know how to install/use (really, I've spent like half an hour reading through the documentation and I don't even understand how am I supposed to install it), and Cygwin, which I've already installed but I don't know how to

Why are typedef identifiers allowed to be declared multiple times?

故事扮演 提交于 2019-11-27 02:43:44
问题 From the C99 standard, 6.7(5): A declaration specifies the interpretation and attributes of a set of identifiers. A definition of an identifier is a declaration for that identifier that: for an object, causes storage to be reserved for that object; for a function, includes the function body; for an enumeration constant or typedef name, is the (only) declaration of the identifier. If identifiers with typedef are in fact definitions, then why are they allowed to be declared more than once?

Variable length array in the middle of struct - why this C code is valid for gcc

穿精又带淫゛_ 提交于 2019-11-27 02:34:27
问题 There is some strange code using VLA (Variable Length Arrays) which is treated as Valid C (C99, C11) by gcc 4.6: $ cat a.c int main(int argc,char**argv) { struct args_t{ int a; int params[argc]; // << Wat? // VLA in the middle of some struct, between other fields int b; } args; args.b=0; for(args.a=0;args.a<argc;args.a++) { args.params[args.a]=argv[0][0]; args.b++; } return args.b; } This code compiled without warnings: $ gcc-4.6 -Wall -std=c99 a.c && echo $? 0 $ ./a.out ; echo $? 1 $ ./a.out

Is int main() { } (without “void”) valid and portable in ISO C?

依然范特西╮ 提交于 2019-11-27 02:11:35
问题 The C standard specifies two forms of definition for main for a hosted implementation: int main(void) { /* ... */ } and int main(int argc, char *argv[]) { /* ... */ } It may be defined in ways that are "equivalent" to the above (for example, you can change the parameter names, replace int by a typedef name defined as int , or write char *argv[] as char **argv ). It may also be defined "in some other implementation-defined manner" -- which means that things like int main(int argc, char *argv[]

Does C99 guarantee that arrays are contiguous?

你离开我真会死。 提交于 2019-11-27 01:36:08
Following an hot comment thread in another question, I came to debate of what is and what is not defined in C99 standard about C arrays. Basically when I define a 2D array like int a[5][5] , does the standard C99 garantee or not that it will be a contiguous block of ints, can I cast it to (int *)a and be sure I will have a valid 1D array of 25 ints. As I understand the standard the above property is implicit in the sizeof definition and in pointer arithmetic, but others seems to disagree and says casting to (int*) the above structure give an undefined behavior (even if they agree that all

Setting std=c99 flag in GCC

♀尐吖头ヾ 提交于 2019-11-27 00:59:54
I was wondering if there were any files in which I could set the -std=c99 flag, so that I would not have to set it for every compilation. I am using GCC 4.4 on Ubuntu. Instead of calling /usr/bin/gcc , use /usr/bin/c99 . This is the Single-Unix-approved way of invoking a C99 compiler. On an Ubuntu system, this points to a script which invokes gcc after having added the -std=c99 flag, which is precisely what you want. How about alias gcc99= gcc -std=c99 ? 来源: https://stackoverflow.com/questions/2193634/setting-std-c99-flag-in-gcc

Type punning with void * without breaking the strict aliasing rule in C99

风流意气都作罢 提交于 2019-11-27 00:56:21
问题 I recently came across the strict aliasing rule, but I'm having trouble understanding how to use void * to perform type punning without breaking the rule. I know this breaks the rule: int x = 0xDEADBEEF; short *y = (short *)&x; *y = 42; int z = x; And I know that I can safely use a union in C99 for type-punning: union{ int x; short y; } data; data.x = 0xDEADBEEF; data.y = 42; int z = data.x; But how do I use void * to safely perform type-punning in C99? Is the following correct: int x =

Why are there digraphs in C and C++?

依然范特西╮ 提交于 2019-11-27 00:47:41
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? 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 I believe that their existence can be traced back to the possibility that somewhere, somebody is using a compiler with an operating system whose character set

What are those strange array sizes [*] and [static] in C99?

≡放荡痞女 提交于 2019-11-27 00:36:58
问题 Apparently the following function prototypes are valid in C99 and C11: void foo(int a[const *]); void bar(int a[static volatile 10]); What is the purpose of those strange subscript notations * , static , and CV qualifiers? Do they help distinguish statically typed arrays from variable-length arrays? Or are they just syntactic sugar? 回答1: static in parameter array declarator void f(int a[static 10]); static here is an indication that parameter a is a pointer to int but that the array objet