1,966 questions
13
votes
3
answers
951
views
Is strtol(str, &str, 10) legal in C99 due to restrict aliasing?
Consider the following code:
char *str = "1234";
long n = strtol(str, &str, 10);
The prototype of strtol() in C99 is:
long strtol(const char *restrict nptr, char **restrict endptr, int ...
14
votes
3
answers
971
views
Is passing NULL valid when array parameter uses [static 0] in C99?
Consider the following code:
void foo(size_t len, int array[static len])
{
}
int main(int argc, char *argv[])
{
foo(0, NULL);
return 0;
}
The function foo declares its second parameter using ...
1
vote
1
answer
104
views
Is enum conversion safe provided that the target data type is forced to be big enough with a big-valued constant?
I'm writing a software in C99 which consists of two git repositories, one of them a submodule.
The submodule declares an error code enum in a header:
enum err_cause {
ERR_CAUSE_A = 1,
...
4
votes
3
answers
251
views
Does the C99 standard allow anonymous enums?
I know that anonymous structs and anonymous unions are a GCC extension that was recently introduced to the C11 standard:
struct named {
int type;
union {
struct {
int a;
int b;
...
1
vote
0
answers
72
views
SDL3 does not report SDL_EVENT_WINDOW_MINIMIZED on KDE Plasma
I am using SDL3 and I am running on a KDE Plasma DE.
I have the following Event Loop:
void platform_poll_events(platform_t* p, input_state_t* input) {
SDL_Event evt;
while(SDL_PollEvent(&...
3
votes
2
answers
106
views
using isinf() on IRIX-6.5
I'm doing a bit of retro-computing and try to build one of my pet projects on an SGI Indy running IRIX-6.5.
$ uname -a
IRIX IRIX 6.5 10070055 IP22
$ which gcc
/usr/freeware/bin/gcc
$ gcc -version
...
8
votes
2
answers
292
views
Is it UB in C99 to access the first member of a struct via a pointer of another struct type when the first member item is identical?
If we have similar structs (Base, Derived1 and Derived2) that both have a first element of type int:
typedef struct stBase {
int type;
} Base;
typedef struct stDerived1 {
int type; // same ...
5
votes
1
answer
249
views
MISRA C:2012 violations with enums in C99
I'm working on a C99 project that is required to follow the MISRA C:2012 standard.
Whenever I use an enumeration type, I get a violation of rule 10.4 or 10.5.
As a static analysis tool, I use the code ...
Best practices
3
votes
6
replies
154
views
Avoiding array duplication in big integer routine
I am working on a multiplication routine in a big integer library in POSIX C99 with a signature of bigint_st *bigint_mul(bigint_st *dest, const bigint_st *a, const bigint_st *b). Many of the routines ...
14
votes
4
answers
1k
views
Is there an `alignof` implementation portable to standard C89 and C99?
C89 and C99 do not provide an alignof macro as part of the standard library (nor an alignof keyword as part of the language as done by C23).
C programmers found out they can define their own version ...
4
votes
1
answer
249
views
Size of anonymous struct standard conformant?
In C89 and C99: Is sizeof on anonymous structs standard conformant?
sizeof(struct{long l; void* ptr;})
0
votes
1
answer
109
views
Bounds-checking SDL_Surface::pixels?
In the SDL_Surface structure, is there
a way to calculate the bounds of the pixels
Member?
I need a quicker way of doing this, so my code doesn't catch seg-faults while running.
On my Linux Laptop, ...
0
votes
1
answer
291
views
GCC -Wunsuffixed-float behaviour
(major edit of the question)
I'm using arm-none-eabi-gcc 10.2.
The following code
const double d = 1.0;
int main()
{
return d*d;
}
compiled with
arm-none-eabi-gcc -Wall -Wextra -Wpedantic -...
3
votes
3
answers
258
views
Is it thread-safe to access different elements of an array in C99?
char my_array[10];
Let's say threadA changes the value of my_array[0] and threadB changes the value of my_array[1], is this thread safe?
A similar question has already been asked Is access to ...
5
votes
3
answers
187
views
Can code use size_t instead of ptrdiff_t when subtracting two pointers where the minuend >= subtrahend and the result is guaranteed to be < SIZE_MAX?
size_t array_len = SIZE_MAX;
int *my_array = calloc(array_len, sizeof(int));
int compar(const void *n_to_search, const void *arr_element)
{
if(*(int *)n_to_search > *(int *)arr_element)
...