Skip to main content
Filter by
Sorted by
Tagged with
3 votes
1 answer
68 views

Casting pointer-to-intptr_t to pointer-to-pointer

A pointer can be safely cast to intptr_t (or uintptr_t) and back (on platforms where those types exist), but what about casting a pointer-to-intptr_t into pointer-to-pointer and using that to modify ...
njlarsson's user avatar
  • 2,478
1 vote
1 answer
183 views

Why does this ANTLR4 grammar complain about C code that is obviously legal and compilable?

I'm writing a tool in Kotlin using ANTLR4 with this nicely working grammar: Grammar for C11 by Sam Harwell The grammar works fine, my tool works. But suddenly I ran into a problem. One C source made a ...
jazz64's user avatar
  • 386
1 vote
1 answer
124 views

Tagging pointers & well-defined ways to create a misaligned pointer

C11 6.3.2.3p7 says: A pointer to an object type may be converted to a pointer to a different object type. If the resulting pointer is not correctly aligned 68) for the referenced type, the behavior ...
Petr Skocik's user avatar
  • 60.5k
1 vote
2 answers
107 views

Why std=c11 allows using of nonstandard functions?

I can compile and run a program that includes <getopt.h> and uses getopt_long with keys -std=c11 --pedantic-errors. Can you explain why?
Akramat's user avatar
  • 163
2 votes
1 answer
116 views

C11: are rules of reserved identifiers irrelevant if library is not used?

In C11 rules of reserved identifiers are defined in the library clause (clause 7). Hence, are rules of reserved identifiers irrelevant if library is not used? Note: in C23 rules of reserved ...
pmor's user avatar
  • 6,727
4 votes
1 answer
79 views

The sequential consistent order of C++11 vs traditional GCC built-ins like `__sync_synchronize`

So I've came across Jeff Preshing's wonderful blog posts on what's Acquire/Release and how they may be achieved with some CPU barriers. I've also read that SeqCst is about some total order that's ...
Not A Name's user avatar
2 votes
4 answers
154 views

Is { struct-declaration-list } a block?

Is { struct-declaration-list } in C11 (as known as { member-declaration-list } in C23) a block? The original issue: I cannot find the exact definition of the term "block" in the C standard (...
pmor's user avatar
  • 6,727
2 votes
1 answer
76 views

Does the the 2+2W litmus test code in the 'Repairing Sequential Consistency' paper have a problem?

I was reading the paper Repairing Sequential Consistency in C/C++11 by Lahav et al and had a doubt regarding the 2+2W litmus test presented there. Under the section Semantics of SC Atomics in C11, ...
Dhwani Katagade's user avatar
6 votes
1 answer
206 views

Can a C compiler legally reject a program if its call stack depth exceeds a fixed limit at compile time?

I've read that C doesn't mandate a minimum stack size, leaving it implementation-defined. But could a conforming C compiler refuse to compile a program if it detects--say, through static analysis--...
Alphin Thomas's user avatar
1 vote
1 answer
94 views

Does assigning a volatile variable to itself suppress compiler optimization in a loop?

I'm working on a delay loop in C and come across an odd case with volatile. Consider this code: void delay(unsigned int count){ volatile unsigned int timer = count; while (timer > 0){ ...
Alphin Thomas's user avatar
2 votes
2 answers
120 views

Function-like macro in C11 _Generic

I would like to use _Generic to expand function-like macro instead of function in C: #include <stdio.h> #define VAL_V(X) X #define VAL_P(X) *X #define VAL(X) _Generic((X), int: VAL_V, int *: ...
MaPo's user avatar
  • 877
1 vote
1 answer
138 views

Require trailing comma

My application is written in C99 (or rather GNU99, and I wouldn't mind going to GNU11), and I'd like to require trailing commas in structure initializers. Does GCC have a warning (turned into error ...
Radim Vansa's user avatar
  • 5,898
0 votes
4 answers
128 views

Using = operator on atomic variable?

Is newNode->next = NULL; an undefined behavior in this case? struct node { int value; _Atomic(struct node*) next; }; //at the initialization stage struct node* newNode = malloc(sizeof(struct ...
Mr.nerd3345678's user avatar
3 votes
1 answer
171 views

Math error conditions (C99, C11, etc.) in GCC

With ISO C99 onward we have a few macros (or constants) that help understanding how some math errors (see <math.h> related) are signaled. However, to me it looks like they haven't been ...
LuC's user avatar
  • 433
5 votes
1 answer
137 views

What is the order of evaluation of VLA dimensions?

Is the following code: #include <stdio.h> void case1(int array[][printf("hello ")][printf("world ")]) {} int i = 0; void case2(int array[][i++][i++]) {} int main(void) { ...
KamilCuk's user avatar
  • 145k

15 30 50 per page
1
2 3 4 5
…
62