44 questions from the last 7 days
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 ...
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 *...
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, ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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(...
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 ...
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 ...
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-...
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 *));
...