Questions tagged [c99]
This tag is for questions regarding the International Standard ISO 9899:1999, aka "C99", with technical corrigenda, and for questions about code written in C99 (as opposed to K&R C, C89 or later C Standard revisions like the 2011 revision C11).
1,892
questions
0
votes
1
answer
20
views
min-GW gcc cant link winsock2.h
I'm trying to use winsock2 library, i'm using it to compile tutorial server from open62541
some code that i used and make error (from open62541.c that built from amalgamation):
#include <winsock2....
1
vote
3
answers
83
views
Why can't I make an array of structs with bitfield?
Edit: I had to use union for that purpose specifically, because the chapter is about them. The fragment of the first task which the one I speak of is based on:
Design a union named byte_set, which ...
0
votes
2
answers
54
views
Concatenate preprocessor tokens
How to write a macro #define CONCATENATE(x) that will produce the following results:
CONCATENATE(int); // Produce --> int
CONCATENATE(unsigned int); // Produce --> unsignedint
CONCATENATE(long ...
0
votes
1
answer
34
views
CLONE_IO does not fit into the range of the "flags" parameter of clone()
According to the man page of clone, the third parameter of clone (flags) is of type int. The man page offers to pass CLONE_IO through this parameter, which, however, seems to be defined as 0x80000000, ...
-2
votes
0
answers
15
views
C-Lion auto code completion does not work
I downloaded C-lion recently for a course in the University
They asked us to download WSL with Ubuntu and to use WSL CMake as our compiler, and also use C99.
After a long battle I manages to do all ...
0
votes
3
answers
72
views
Any way to get fdopen functionality with C99?
Apparently fdopen requires a POSIX/gnu99 using compilation standard. I am hoping to stay on C99.
I am running into this problem because I use open() to create a file descriptor and then (because I use ...
2
votes
2
answers
98
views
Initialize block-scope static const variable with pointer to compound literal?
The following code is rejected by GCC and Clang (godbolt link):
struct thing;
typedef enum {
THING_TYPE_A,
THING_TYPE_B,
} thing_type_t;
typedef struct thing_a {
int i;
} thing_a_t;
typedef ...
1
vote
2
answers
74
views
How do I write a string into a file in C without writing (null)? [closed]
This is what I have got:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main(int argc, char* argv[]) {
unsigned short index;
...
0
votes
1
answer
31
views
mixing pointers to signed and unsigned in C
Suppose I have an integer variable with non-negative value and two pointers to it - one signed and one unsigned pointer. As far as I can tell from the standard, this is fine.
6.5
An object shall have ...
2
votes
1
answer
64
views
operation reordering and signedness in C
I found several questions discussing compiler optimizations for signed vs unsigned.
The general conclusion is that signed allows for more optimizations due to the undefined behavior of overflow.
...
0
votes
1
answer
27
views
Implicit declaration of function 'FillOutASBDForLPCM' is invalid in C99
When implementing the predefined inline C++ method, I am getting
Implicit declaration of function 'FillOutASBDForLPCM' is invalid in
C99
error. Please help me what i made the mistake or Do i import ...
1
vote
0
answers
10
views
realloc printing old contents
realloc still prints old content even reallocated size is decreased.
until i add null byte to the end of the string.
-fsanitize=address gives error ==7126==ERROR: AddressSanitizer: heap-buffer-...
0
votes
1
answer
56
views
How to get debug interface for directx 11 in C
Trying to follow this example:
DirectX11 ReportLiveObjects Instantiation
I'm trying to get a debug interface setup using C99 with directx11. I've already defined COBJMACROS and CINTERFACE in order to ...
1
vote
0
answers
62
views
No output for MSVC 2015! What to do? Should I change the C Standard on IDE?
Here's the c code:
#include <stdio.h>
typedef char charray5[5];
charray5 carr1 = { 'a', 'b', 'c', 'd', '\0' };
charray5 carr2 = { 'q', 'w', 'e', 'r', '\0' };
charray5 carr3 = { 'x', 'y', 'z', '...
1
vote
0
answers
34
views
How does realloc returns NULL when it failed to allocate memory?
I am beginner in C. Currently I am learning about dynamic memory allocation. I have learned that void pointer returns nothing but when i got to know syntax of realloc I couldn't understand how it is ...
0
votes
0
answers
7
views
How can I use an array to store a user-input and be able to use that array in a future print?
Good morning. I am currently trying to write a program where the basis of it is that the program is able to store a user-input and reiterate that input in another manner.
#include <stdio.h>
int ...
3
votes
5
answers
137
views
Is there a way to init a C double with a const value based on a hex pattern?
I have a need to put an invalid hex pattern into a C-99 double value.
Unfortunately, this does not work (for obvious reasons):
const double invalid_double = 0x7ff0000000000001;
Neither does this (...
1
vote
0
answers
76
views
lld-link error: undefined symbol: __sbsan_handle_out_of_bounds
I'm trying to test clang's -fsanitize=array-bounds compiler flag with some c99 code on Windows but I can't compile due to a linker error. My test code is this:
int index = 11;
int arr[10] = { 0 };
...
0
votes
0
answers
22
views
How to fix clang handle_out_of_bounds error
I'm currently compiling my C99 code with clang's compiler flag -fsanitize=array-bounds and it produced a "__ubsan_handle_out_of_bounds" error here:
void _add_entry(const char* api_name, void*...
-1
votes
1
answer
55
views
How to use a c99 compiler on PC
I have CodeBlocks 13.12 and I want to compile a c99 code on it. Is there any way I can do this. If there is any other way to compile a c99 code, that is okay as well.
Thanks!
-4
votes
2
answers
46
views
Passing a ' character as a command line argument seems to start a prompt in C on Ubuntu [closed]
hope someone can help.
I'm working on a problem set passing arguments in C99 on Ubuntu, part of the problem set specifies that non-integer characters should lead to an early return from the main ...
1
vote
1
answer
31
views
Error initializing nested struct containing array of struct and function pointer c99 and gnu99
I am getting error during initialization of nested structure containing two members
unsigned int
typedef void (*vfptr)(void);.
The first structure or parent structure contains simply two variables ...
0
votes
1
answer
32
views
error: no C99 compiler found, eudev requires a C99 compiler
I executed the command "make" after the configurations on the menuconfig of buildroot and then this error appeared.
It appears when i enable eudev.
Can someone help me???
when i do gcc --std=...
3
votes
0
answers
53
views
rescan for macro replacement?
By reading here
(where I cannot add comments-questions as I am new on StackOverflow),
it is explained that with the definitions
#define foo(X) 1 bar
#define bar(X) 2 foo
then
foo(X)(Y)(Z)
expands to
...
0
votes
0
answers
27
views
What can i do to decrease the completing time and make my code go faster at this little program(A program that prints narcissistic numbers)) [duplicate]
#include <stdio.h>
#include <math.h>
#include <time.h>
int main(void){
clock_t start=clock();
for(int i=1;i<=11;i++){
long long multi=(long long)pow(10,i-1);
...
0
votes
0
answers
42
views
How to store values in a array inside other function
I've started learning C. I'm doing functions right now.
In these exercise they want me to ask for a value that means an error. If they input the number 8, it means that it's error "8", if ...
5
votes
1
answer
157
views
Multi-dimensional array of unknown bounds argument : difference between C and C++
The following program compiles as a C program:
#include <stdlib.h>
#include <stdio.h>
void f(int n, int m, int x[n][m]) {
printf("x[0][2] = %i\n",x[0][2]);
}
int main() {
...
0
votes
0
answers
17
views
change comma to dot in c string
I want to change the ',' of the string and put a '.' at the place
unsigned long GetStringLength(const char* InString){
if(InString[0] == 0) return 1;
return 1 + GetStringLength(InString + ...
0
votes
0
answers
48
views
Typedefs for available/unavailable types
I have a C module foo.c which defines a function
json_t* foo_to_json(foo_t*);
The user of this code may or may not have the Jannson library available, I check that with autoconf, feed the value in by ...
0
votes
0
answers
57
views
Combining of two adjacent stack allocated arrays in C
Say I have two arrays, dynamically allocated on the stack using C99 features. Due to the compiler's freedom of being able to reorder such arrays however it likes, and by great desire to out of bounds ...
0
votes
0
answers
37
views
Array and structures initialization
Firstly, I'll put this in the short form: How can I initialize the structure and vector below with the desired values (0xFF and 0x41)?
#include <stdio.h>
typedef struct
{
unsigned char var1[...
0
votes
0
answers
30
views
What's the proper way to tell MinGW based gcc to use ANSI stdio output (on Windows)?
I want my Windows C program compiled with GCC on MinGW64 toolchain to output inf, -inf etc. ANSI values instead of Windows specific one like 1.#IND.
So far I was adding the following line before ...
0
votes
1
answer
70
views
Can static array indices be used with opaque struct types?
There is an opaque structure that I want to rewrite a function for:
// Set.h
typedef struct Set Set;
void Set_Function(Set* self);
I would like to modify the function to indicate to the developer ...
2
votes
2
answers
48
views
Using sizeof on Flexible member array's first element before memory allocation is Undefined Behaviour?
If we have structure with flexible member array like :-
struct test{
int n;
int b[];
};
Then even before malloc is done, If we try to print like :-
struct test t;
printf("%lu",...
1
vote
1
answer
80
views
How to disallow literal string but not dynamic string pointers in C function arguments
This is my very first question here, I think.
I wrote my C code trying to respect "-Wall -Wextra -Werror -ansi -pedantic", but I can be flexible.
I wrote a function with the following ...
0
votes
1
answer
87
views
C99 The reason float value 1.000000 turns into 3.000000?
#include<stdio.h>
int main()
{
float x = 1.0;
int *p=(int *)&x;
*p=1077936128;
printf("x=%f, *p=%d\n",x,*p);
}
The result is x=3.000000, *p=1077936128 .
I can't ...
2
votes
1
answer
34
views
Asking the syntax of Function pointer. - int (int)
I've learned function pointer is used as :
double (*ptr)(double)
ptr = my_func1;
And also, using 'typedef' could be
typedef double (*func1)(double);
func1 my_func1;
But I can't understand why this ...
2
votes
2
answers
46
views
Can pointer of specific type be assigned to pointer to union which contains the same type as one of it's members?
Let's say I have following piece of code, defining a structure and a union:
struct Foo
{
int i;
float f;
};
union Bar
{
struct Foo foo;
char buf[10];
};
Is it safe to assign pointer ...
4
votes
3
answers
84
views
Is it valid to check if a function is defined in C?
void f();
int main(int argc, char** argv)
{
if (f)
{
// other code
}
}
With VS2017, the linker complaint about unsolved external symbol, while it works with GCC. According to C99 ...
0
votes
1
answer
67
views
How is a C function pointer laid out in memory
There's some information about how struct is laid out in memory in a C process. I wanted to know how a function pointer is laid out in memory.
e.g.
void (*fun_ptr)(int)
0
votes
1
answer
69
views
Parsing user input from whitespaces in C
I am trying to parse user input from scanf() by using the white spaces. I wanted to separate each string as I will be using them as commands in UNIX.
Example
input: ls -l
Expected output:
This is a ...
0
votes
0
answers
131
views
Are there any platforms with nonzero null pointer values? If so, how common are they? [duplicate]
I've given up here and I'm starting over with a clean new question 😭
Let me try to rephrase the question as objectively and simply as possible:
I want someone to either give me a list of platforms (...
3
votes
1
answer
130
views
Compatibility between void * and char *
Are void and char pointer guaranteed to have the same memory representation?
In other words, after executing the following:
char a = 'z';
void *b = &a;
char *c;
memcpy(&c, &b, sizeof(b));
...
1
vote
1
answer
96
views
Why does the standard C library feature multiple header files instead of consolidating the contents into a single header? [closed]
Why does the standard C library need to feature multiple header files? Would it not be more user friendly to consolidate it into one header file?
I understand that it is unnecessary to include ...
0
votes
1
answer
163
views
Plot a function using Gnuplot with C99
I want to plot the sinus function with Gnuplot using C99 on CLion from JetBrains (Windows 10). I have been given a code that is supposed to work:
#include <stdio.h>
#include <stdlib.h>
#...
-1
votes
1
answer
65
views
Required Dependencies for Redistribution of pure C (NOT C++) Library
Background:
I am currently writing a .dll library using Visual C (NOT C++) which intends to provide performance-optimized functionalities for other applications. All functions in this library fulfill ...
0
votes
1
answer
33
views
Undefined behaviour on deleting a node in linked list
So I am trying to delete a node in a doubly linked list, given only a pointer to the node. This is my code:
void deleteNode(Node* node) {
if(node == NULL) {
return;
}
if(node-&...
0
votes
1
answer
65
views
Is there a way to use designated initializers to initialize parts of the same array in separate files?
I have thousands of "commands" that are all defined in their own files, and I want to be able to do things with them programmatically using an enum as a key.
The only way I can think of to ...
0
votes
0
answers
75
views
std=c99 on gcc 4.3.3, I get warning: implicit declaration of function ‘gmtime_r’
Using an admittedly old compiler, I'm trying to compile code that uses functions like nan(), swprintf(), and other C99 features. I add the -std=c99 argument to CFLAGS, and those issues get fixed, but ...
1
vote
1
answer
188
views
Printing a string in C without declaring a variable
I've couldn't find an already existing source for this so I've come to ask here.
If you know a good source that I can refer to please let me know it by comments.
Looking at many textbooks and ...