Questions tagged [c89]
This tag is for questions regarding the international standard ISO 9899:1990, also known as "C89", "C90" or "ANSI C", with amendments and technical corrigenda (as opposed to K&R C, C99, C11 or later C standard revisions).
633
questions
3
votes
1
answer
51
views
How can I avoid repeating myself in C89 when defining the same function for multiple types?
I am writing a simple dsp library in c89. It is a goal to use this version of the language for portability to older machines. I am unit testing my library and want to measure the amplitude response of ...
3
votes
1
answer
58
views
Why does GCC C89/C90 ANSI C use __STDC_VERSION__ in Eclipse?
I need to confirm my code if I'm using ANSI C (C89/C90) and I notice this:
Even if I have selected ASNI C (C89/C90) standard in Eclipse CDT.
Question:
It is told that ANSI C does not use ...
3
votes
3
answers
128
views
Taking sizeof of variable-length array — is there any benefit for doing so?
I am working on a piece of legacy code (no tests). I stumbled upon a section hidden inside several macros. It generates a warning if compiled with GCC's -Wvla.
The code in question is equivalent to ...
0
votes
1
answer
40
views
Copying void-pointer element into void-pointer array causes multiple copies of element in array
I'm trying to code a TreeSort function in C89 for practice with a qsort parameters i.e. (void* base, size_t num, size_t size, int (*compare)(const void*, const void*)). I've implemented sort function, ...
0
votes
2
answers
93
views
Deduplication optimization
The problem is as follows. I want a function that, given a list and a max number of occurrences "x", deletes all elements of the list that appear more than x times or x times.
I found a ...
-3
votes
1
answer
72
views
C Program returning an error... google doesn't know
The following code takes an array of integers and create an array with the mobile means (i.e. the value in i-th place is the mean of the last n elements in the array before i (if they exists); if i<...
2
votes
2
answers
84
views
When was random() introduced in C and why does standard 89 not recognise it?
I’m working on a Operating Systems project with requirements being the usage of C89 and pedantic flags.
Since I am on macOS, I’ve encountered a fair amount of issues with the rand() function during a ...
0
votes
1
answer
37
views
Filling an array of structs with a for loop in c89
I'm trying to fill a table with structs inside a for loop, and I can't find anywhere how it's supposed to be done. Here is the code for the struct :
#define LEN 255
typedef struct {
int number;
...
0
votes
0
answers
27
views
How can I edit this code so it compiles on ISO C90 and not just ISO C99? [duplicate]
I'm currently running a shell project, I tried to compile the code using: `
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh
The compilation method is mandatory for my project. The code ...
0
votes
0
answers
157
views
Compliling c programs to C89/C90 standard in VSC
I'm learning C90/90 in uni using MinGW compiler.
Now I want to use VSC instead of CodeBlocks which my prof uses.
How would I go about changing the compilers settings to disallow any functions that are ...
-3
votes
1
answer
65
views
Why does clang c89 have powf, but gcc c89 doesn't? [closed]
Isn't the c89 standard supposed to be consistent ?
I'm compiling with gcc -W -Wall -std=c89 -pedantic -O3
On macOS, gcc is an alias of clang it seems : gcc --version returns Apple clang version 14.0.0 ...
0
votes
2
answers
76
views
Why is there no compilation error with those array declarations (C89-C90)?
I want to show that arrays can't be defined with a variable for the length in C89 or C90.
I use GCC on Windows from TDM GCC:
C:\TDM-GCC-64\bin> .\gcc.exe --version
gcc.exe (tdm64-1) 10.3.0
My ...
4
votes
2
answers
192
views
ANSI C conforming platforms where all-bits-zero is not a null pointer representation
Are there any ANSI C conforming environments where all-bits-zero is not a representation for a null pointer? That is, environments where the following program would print 0? If so, can you list some ...
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 (...
0
votes
2
answers
45
views
Making a bordered 2D array (C89)
I'm trying to make a 2D array that can be a varying size based on user input however with the code I have right now whenever the user inputs the size of the 2D array it does not print a '#' layer at ...
0
votes
1
answer
39
views
Segmentation Fault - malloc 2D array
Trying to create a map for a little game. When initialising the map with 2D arrays using malloc, the main function will run okay when the printMap function is commented out, however when trying to ...
1
vote
1
answer
96
views
Error when dynamically allocating a 2D array - ISO C90 forbids variable length (C89/C90)
I'm trying to program up a 2D dynamically allocated array for a map for a small game. Below is my code, I'm unsure why int* array[yCoord] is throwing up the error that it cannot be a variable length ...
1
vote
2
answers
44
views
Saving the updated value of the variable, for the next call of the function?
My code below is trying to output the next power of 2 when the program is run, so ./powers would return 4, then if I run again, ./powers would return 8.
However it returns 4 every time, how do I get ...
0
votes
0
answers
106
views
Ansi-C 89 - Copy two .txt's, fgetc not working some how
I am preparing for my CS exam in procedural programming and my code doesn't work.
The task: Using command line arguments for the path, copy the contents of one text file into another.
Example with cmd....
1
vote
2
answers
67
views
Is casting a pointer to an incompatible type then casting it back before dereferencing defined behavior in C89?
I realize there are lots of "Is this pointer madness defined behavior in C?" questions on this site, but none of the ones I found seemed to be on point, so if this is a duplicate I apologize....
2
votes
1
answer
143
views
Atomic equivalent for C89
So, im programming in C89, and its going well so far except one issue, Im doing multithreaded applications and I need to use atomic.
I dont want to switch to C11 because I want my code to be ...
2
votes
3
answers
190
views
C: Portable way to define Array with 64-bit aligned starting address?
For code that is compiled on various/unknown architectures/compilers (8/16/32/64-bit) a global mempool array has to be defined:
uint8_t mempool[SIZE];
This mempool is used to store objects of ...
0
votes
1
answer
97
views
Why does the C standard state that string literals shall begin and end in the initial shift state?
The ANSI X3.159-1989 "Programming Language C" standard states in the chapter "5.2.1.2 - Multibyte characters" that:
For the source character set, the following shall hold:
A ...
1
vote
1
answer
116
views
Can the "null character" be represented as a multibyte value in C language?
The ANSI X3.159-1989 "Programming Language C" standard states in the chapter "5.2.1.2 - Multibyte characters" that:
For both [source and execution] character sets the following ...
0
votes
2
answers
91
views
fgets and sscanf in C
I have a file I'm trying to extract the integers and characters out of.
10 20
0 0 #
1 0 |
2 0 |
3 0 |
3 1 -
3 2 -
3 3 -
3 4 >
My current code is:
while(fgets(line, sizeof(line), snakeFile) != NULL)...
0
votes
2
answers
80
views
C/C90/Counting words in large text file
I have a text file which consists of about 30000 words. My goal is to count the actual number of the words (keep in mind that multiple punctuation marks and consecutive spaces are included, as well as ...
0
votes
0
answers
52
views
How to execute an arbitrary command using the openssh library in C
I am a beginner C programmer, I got an old project use openssh library(https://github.com/openssh/openssh-portable) in which I need to connect via SSH and execute a set of commands on the device. I ...
-1
votes
4
answers
377
views
Have the code examples from K&R ever been conforming?
The C Programming Language by Brian Kernighan and Dennis Ritchie contains a lot of examples such as this famous one (K&R 2nd edition 1.1):
#include <stdio.h>
main()
{
printf("hello, ...
0
votes
3
answers
162
views
C89: declare large const array, then use it, then initialize it
This is purely for readability. I want to have a very large constant array of values, but it makes my file a lot less pleasant to read. So I'd like to have that array initialized after use, though I ...
3
votes
6
answers
163
views
Remove white chars between commas, but not between what inside the commas
I'm new to C and learning C90.
I'm trying to parse a string into a command, But I have a hard time trying to remove white chars.
My goal is to parse a string like this:
NA ME, NAME , 123 456, 124 ,...
1
vote
2
answers
72
views
File manipulating code ends in an unexpected way-C90 [duplicate]
The code :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100000
#define N 40
int get_choice(void);
int check_word(char *word);
void insert_text(FILE ** ...
-1
votes
1
answer
68
views
Various issues while dealing with files -C90
The problem(actually various problems):
if choice != 0 either the insert_text function is called or add_word_in_dictionary
is called which is not wanted..
I want to create a function which saves a ...
1
vote
1
answer
84
views
Why is NULL printed here? - C-90
The code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 500
#define M 100
/*Version 1*/
void replace_word(char *word);
void add_new_word_dictionary(void);
...
0
votes
0
answers
31
views
Cannot call a function under a specific condition-C90
The code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*Version 1*/
void replace_word(char *word);
void add_new_word_dictionary(void);
void do_nothing(void);
void ...
1
vote
0
answers
113
views
When and how to initialize standard I/O streams (stdin, stdout, stderr)?
Experimenting with static binaries, I found myself reimplementing parts of libc. My libc is static (i.e. a .a archive,) targets 64-bit Linux only and will probably never be POSIX compliant but I'm ...
2
votes
3
answers
831
views
C program to remove consecutive repeated characters from string
The code: https://pastebin.com/nW6A49ck
/* C program to remove consecutive repeated characters from string. */
#include <stdio.h>
int main() {
char str[100];
int i, j, len, len1;
...
0
votes
1
answer
109
views
Qt Creator with C/C++ warns about padding for enums
So I have a data structure that entirely consists of :
unsigned char i.e. byte-sized attributes
bool_T which I have typedefd to unsigned char (if C) or to bool (if C++) so again byte-sized
enums ...
0
votes
1
answer
35
views
Optimize function to order a two-dimensional array by the value of its position 0 in C
double generation[genomes_per_generation][amount_of_variables];
double ranked_generation[genomes_per_generation][1 + amount_of_variables];
double tmp[1 + amount_of_variables];
int i, j, k;
for (i = 0; ...
0
votes
2
answers
114
views
Implementing trigraphs in a C89 compiler
I am attempting to write a simplistic C89 --> x86_64 compiler, based on this C89 standard draft, in C89, for learning's sake. So far, I am implementing translation phase 1. My understanding is that ...
3
votes
2
answers
124
views
Is the format specifier %[^\n]s legal in C89?
I'm reading a string from sdin with a scanf by doing:
scanf("%[^\n]s", msg);
%[^\n]s reads till a new line character is found. Is this legal in ANSI-C?
0
votes
2
answers
581
views
Use printf with args into variadic functions?
I need a function that works like printf, but makes some changes to the fmt string: for example, add at the beginning a string containing the datetime, but the rest, I will maintain the same printf ...
0
votes
1
answer
64
views
Need Help Finding Segmentation fault in C Program
I'm implementing the Data Encryption Standard in C for a personal learning project and I have a seg fault that has been driving me up the wall for the past 3 days. I understand this isn't the place ...
0
votes
1
answer
2k
views
How can i use option -std=c99 in vscode to run programs in c?
I can only run program in C89, but how can i do it with c99? Sorry for a stupid question, I am a newbie
0
votes
1
answer
71
views
Modulo (%) in C returning undefined result compared to the same function in Python? [duplicate]
I am writing a (what I thought) was a simple program implementing the affine cipher and have come across an issue in that I am not getting expected results from the modulo in C89.
int main()
{
foo(...
0
votes
0
answers
47
views
Trouble with passing by reference with linked lists in c
I am trying to create a new node and add it to my linked list, however inside the function I can give the data in the new node the correct value and assign it to the head of the list, but back in main,...
1
vote
2
answers
241
views
Using snprintf with C90
Is there a way instruct the the compiler that:
The language is C90
The declarations of stdio.h are those of C99 (including snprintf)
With cc -std=c90 -Wall (on a source file using snprintf), an ...
-1
votes
3
answers
511
views
Is the GCC option -Wdeclaration-after-statement purely stylistic?
Is the option -Wdeclaration-after-statement stylistic only? By that I mean, if I macro'd all cases in my C code where a variable was defined and I initialized them in them in the same fashion ...
-1
votes
1
answer
184
views
calling scanf inside do while loop is breaking the loop
I have a do while loop. When I run it without scanf(), it runs properly. But if I enter a scanf() it breaks the loop! Why???
The code:
With scanf()
void main(){
int num = prng() % 100, guessed, ...
0
votes
1
answer
110
views
Making sure a value only has to be calculated once ever in C
I have this somewhat complex value (in that it results from combining multiple other values in some mathematically non-trivial way) which however only ever needs to be calculated once in the whole ...
0
votes
0
answers
105
views
Can I cast void * to ptrdiff_t in C89?
Will the C89 standard allow me to cast void * to ptrdiff_t so I can print the memory location as hexadecimal?
For example:
static const char *dig = "0123456789abcdef";
char buf[16], *ptr = ...