Skip to main content
Filter by
Sorted by
Tagged with
7 votes
3 answers
977 views

The Usual Arithmetic Conversions in "C Programming: A modern approach" [closed]

In C Programming: A modern approach 2nd edition, page 143 under section title "The Usual Arithmetic Conversions", I do not understand the 2nd paragraph of this section, as quoted: The ...
Meng's user avatar
  • 173
4 votes
5 answers
131 views

Is array pointer arithmetic undefined behavior in C for separate translation units?

There are several source code files of a program. File file_a.c has an array in the global scope, and a function is provided that returns a pointer to its beginning: static int buffer[10]; int *...
Evgeny Ilyin's user avatar
0 votes
1 answer
213 views

Is it safe to use `(void) va_arg(...)` to advance the `va_list` in C? [closed]

I have a C function that uses va_list but needs to skip the first two arguments in here: static size_t event_type_CURSOR_POS__weight( const void * self, va_list * app ) { (void) va_arg( *app, ...
Sam's user avatar
  • 119
3 votes
2 answers
138 views

C macro to compute array length that returns 0 for NULL

I am writing hardcoded calls of functions that takes array(s) in parameter, e.g. int foo(size_t length, const int array[/* length */]); In order to avoid the error-prone process of keeping track of ...
talentless's user avatar
1 vote
1 answer
180 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
2 votes
1 answer
108 views

What is the purpose of the ar β€œ-l” option?

For context, I have been working on a game engine for a while now. The engine requires several libraries to function (Wayland, XKB, Vulkan, etc.). Because the added complexity of shared libraries ...
Israfil Argos's user avatar
6 votes
1 answer
100 views

When inline function definition and extern function declaration are all present in one .c file, no link error is observed

Even though this might look like duplication, I'd claim that it isn't. Why does a compiler make the Foo function, which is defined in foo.c as inline double Foo() { return 1.2; }, a global function if ...
Stephen's user avatar
  • 735
3 votes
2 answers
111 views

Problems proving trivial things involving shift operators using Frama-C WP

I have this very simple example. /*@ requires a >= 0 && a <= 2; assigns \nothing; ensures \result < 10; */ int bob(int a) { return 1 << a; } When I try to prove this ...
Henrik Sommerland's user avatar
1 vote
2 answers
94 views

Are defect reports applicable to the standards they refer to?

The C11 standard contains a list of defect reports: https://www.open-std.org/jtc1/sc22/wg14/www/docs/summary.htm Do they apply to C11-conforming implementations, or only to later implementations? In ...
anol's user avatar
  • 9,348
6 votes
1 answer
101 views

Call graph verification plugin in Frama-C?

I'm working in a project where we are interested in verifying simple control flow properties of C code. As a first problem, we want to check that a C program conforms to a "white list" of ...
Jesper Amilon's user avatar
0 votes
3 answers
152 views

How to detect whether a variable is allocated on the stack or the heap in C?

I’m working on a C project where I need to know if a pointer refers to memory allocated on the stack or the heap. For example: int x = 42; // stack variable int *y = malloc(sizeof(...
Pawan Bhatta's user avatar
3 votes
1 answer
65 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
3 votes
1 answer
117 views

Pipes Aren't Working: C Programming in the Windows Console [closed]

I've written this small program in C, which intends to read stdin line-by-line and finally echo each line back to stdout. It is designed to stop reading input when either EOF is detected or a blank ...
Peter S. Jaworski's user avatar
3 votes
1 answer
80 views

inline (non-static) function in C-source file

I've seen something like that in a C-code and I'm wondering what it exactly does: file.h int f(int x); file.c inline int f(int x) { ... } Basically the function is declared as inline in the C-...
Kevin Meier's user avatar
  • 2,624
3 votes
3 answers
103 views

What's wrong with this code, which gets content (chars) from file and stores it in char**?

I have a small project (ed-like text editor for myself. Just want to edit some config files using it) and I have some problems with it. workspace_file->flc = malloc(sizeof(char *)); ...
Ho1Ai's user avatar
  • 39

15 30 50 per page