Questions tagged [gcc-extensions]

GCC provides extensions not found in ISO standard C or C++.

45 questions
108
votes
1 answer

What is this "[0 ... 255] =" syntax in C?

Refering to js0n.c The code syntax is as below: static void *gostruct[] = { [0 ... 255] = &&l_bad, ['\t'] = &&l_loop, [' '] = &&l_loop, ['\r'] = &&l_loop, ['\n'] = &&l_loop, ['"'] = &&l_qup, [':'] = &&l_loop,…
Gaurav K
  • 2,864
  • 9
  • 39
  • 68
83
votes
4 answers

What's this C++ syntax that puts a brace-surrounded block where an expression is expected?

I came across this weird C++ program. #include using namespace std; int main() { int a = ({int x; cin >> x; x;}); cout << a; } Can anyone explain what is going on? What is this construct called?
51
votes
4 answers

What is "..." in switch-case in C code

Here is a piece of code in /usr/src/linux-3.10.10-1-ARCH/include/linux/printk.h: static inline int printk_get_level(const char *buffer) { if (buffer[0] == KERN_SOH_ASCII && buffer[1]) { switch (buffer[1]) { case '0' ... '7': case 'd': …
jasonz
  • 1,315
  • 1
  • 17
  • 31
8
votes
2 answers

Are variable length arrays there in c++?

I had always thought that variable length arrays were not allowed in c++(Refer :Why aren't variable-length arrays part of the C++ standard?) .But than why does this code compile and work? #include using namespace std; int main () { …
8
votes
1 answer

How to stop Eclipse CDT from emitting errors due to gcc specific syntax?

I'm writing some code that makes use of computed goto. The syntax checker is flagging every instance of goto *ptr and &&label as syntax error. Is there anyway to stop this? Addition by alk: Example for computed gotos (gcc extension): ... void *…
cleong
  • 7,242
  • 4
  • 31
  • 40
7
votes
2 answers

how to explain this expression "int a=({10;});" in C language?

During my C language practice, I face an expression and then I get it simplified as follows: int a=({10;}); It is a legal expression since it gets past the gcc compiler. Please focus on this part: ({10;}). Is anybody able to explain it? The more…
kevin
  • 765
  • 1
  • 6
  • 16
6
votes
1 answer

Why doesn't GCC's ternary extension support assignment?

GCC has an awesome ternary expression extension to C which allows us to create a statement like this: int x = some_var ?: 10; // expands to some_var ? some_var : 10 Which is really nice, and while it's not particularly intuitive, it does work. Most…
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
5
votes
2 answers

Error: "cannot bind packed field" while inserting data into std::map using insert function

Can somebody tell me the difference between #pragma pack(push,1) and __attribute__((packed))? I am getting a compilation error if I use second type of struct packing which says cannot bind packed field ‘ABC.abc::a’ to ‘unsigned int&’ But if I…
Harry
  • 2,177
  • 1
  • 19
  • 33
5
votes
3 answers

Rewrite GCC cleanup macro with nested function for Clang?

I'm trying to work through an issue on a third party library. The issue is the library uses GCC's nested functions buried in a macro, and Clang does not support nested functions and has no plans to do so (cf., Clang Bug 6378 - error: illegal storage…
jww
  • 97,681
  • 90
  • 411
  • 885
5
votes
3 answers

Are variable-length arrays really not allowed in C90?

I'm reading about VLAs in C Primer Plus, and this book strictly says that the introduction of VLAs to C began with the C99 standard. Whenever I attempt to declare a loop control variable within the header of a for loop, gcc informs me that this…
Theo Chronic
  • 1,623
  • 2
  • 15
  • 16
5
votes
2 answers

GCC typeof extension

I don't understand why this works: /* gcc range extension */ __extension__ static int fn(int n) { switch (n) { case 0: return 0; case 1 ... 1000: return 1; default: return -1; } } But this does not: /* gcc typeof…
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
4
votes
1 answer

Why this compound statement as a sequence of statements enclosed by braces and inside parentheses does not appear to be a valid statement expression

Why this compound statement as a sequence of statements enclosed by braces (in GNU C++) and inside parentheses does not appear to be a valid Statement expression. // my second program in C++ #include using namespace std; int main () { …
K.Karamazen
  • 176
  • 1
  • 8
3
votes
4 answers

How to implement Go's defer() in C so that it allows declaring vars?

In this Modern C video there's a trick that allows to postpone execution of a code until the block/scope exits. It's used as follows: int main() { int foo=0, bar; const char *etc = "Some code before defer"; defer(profile_begin(),…
psprint
  • 349
  • 1
  • 10
3
votes
1 answer

What is the functional difference between "(void) cast" vs. "__attributes__" for silencing unused argument warnings?

Is there any functional difference between marking a virtual method's unused parameter arguments with GCC's __attribute__((unused)) and casting the argument to (void)? class Other { virtual int sum(int a, int b, int c); }; class Example : Other…
ktb
  • 1,498
  • 10
  • 27
3
votes
0 answers

Using gcc/clang C extensions to test if a macro argument is a pointer

Using gcc/tcc/clang's extensions to the C language (C11), is it possible to detect whether a macro argument has a pointer type? Details: I'm using a macro that should take a singly-indirect pointer, but it's tempting to pass a pointer to that…
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
1
2 3