Questions tagged [ansi-c]

ANSI C is an informal term sometimes used when referring to the C programming language standard published by the American National Standards Institute (ANSI) in 1989 .

"ANSI C" is an informal term used to refer to the 1989 version of the C language. The formal name for this version of the language is ISO/IEC 9899:1990. Informally it is also known as "C89" or "C90".

This is because the American National Standards Institute (ANSI) first published this standard in the year 1989, as a national standard for the USA. It became international ISO standard in the year 1990. So ANSI C, C89 and C90 all refer to the same technical standard.

It is a common misunderstanding that "ANSI C" means standard compliant C. The ANSI standard institute haven't had anything to do with C since 1989. The language is maintained by ISO SC22/WG14. Yet the term "ANSI C" is sometimes used to mean standard compliant, particularly in old books and by old compilers.

Because of this ambivalent meaning, please avoid using this tag. For questions regarding the C89/C90 version of the C language, please use . For questions regarding standard-compliant C, simply use the tag.

Further information about the different C standard versions.

618 questions
5
votes
1 answer

Are all functions in C global?

Is it possible that a function in ANSI C cannot be accessed from some other file? How and when functions have limited access? At first I thought that if a function is not included in any header it's private. But it doesn't seem to be the case.
avivgood2
  • 227
  • 3
  • 19
5
votes
2 answers

Finding max value of char in C

I am finding the maximum value of a char by simple addition and testing for when the number goes negative: #include /*find max value of char by adding*/ int main(){ char c = 1; while(c + 1 > 0) ++c; printf("Max c =…
user1717828
  • 7,122
  • 8
  • 34
  • 59
5
votes
5 answers

C89 and variable initialization

C89 (C90, ANSI-C) does not allow intermixing variables declaration with code. I wonder to what extent a variable initialization is considered "code". Perhaps it's only valid to initialize with constant expressions? Specifically, if I'm writing C…
leonbloy
  • 73,180
  • 20
  • 142
  • 190
5
votes
4 answers

What is this code block doing ? (u > 0) - (u < 0)

if (abs(u) > Vdc) u = Vdc*((u > 0) - (u < 0)); This code is in C considering we enter the if condition what will happen ? Vdc = 24; consider any arbitrary value of u for an explanation
Dhruv
  • 645
  • 9
  • 17
5
votes
1 answer

Does ANSI C actually specify which bytes are used when typecasting to a smaller integer?

I'm reading through an email argument regarding the following line of code: p = (unsigned char)random(); The random function returns a long, and somebody says that this is unsafe because it's possible that the typecast might take the MSB instead of…
NapoleonBlownapart
  • 309
  • 1
  • 2
  • 8
5
votes
2 answers

Compliant way to parse a 64 bit integer using sscanf with GCC

I compiled the following c program with gcc -ansi -pedantic -Wall test.c: #include #include #define BUFFER 21 int main(int argc, char* argv[]) { uint64_t num = 0x1337C0DE; char str[BUFFER]; /* Safely Holds UINT64_MAX */ …
recursion.ninja
  • 5,377
  • 7
  • 46
  • 78
4
votes
3 answers

C word size and standard size

in this article, taken from the book "Linux kernel development": http://www.makelinux.net/books/lkd2/ch19lev1sec2 it says: The size of the C long type is guaranteed to be the machine's word size. On the downside, however, code cannot assume that…
Yarel
  • 424
  • 1
  • 6
  • 15
4
votes
5 answers

ANSI C #define VS functions

I have an question about performance of my code. Let's say I have a struct in C for a point: typedef struct _CPoint { float x, y; } CPoint; and a function where I use the struct. float distance(CPoint p1, CPoint p2) { return…
Marnix v. R.
  • 1,638
  • 4
  • 22
  • 33
4
votes
1 answer

Print new line to a text file without carriage return (CR) in windows

I am writing a program in C that prints a random hexadecimal value to a text file. The printed value has a carriage return (CR) along with a line feed (LF). However, the CR (visible in notepad++) is causing issues when the file is used. Is there a…
user968623
  • 53
  • 1
  • 2
  • 6
4
votes
1 answer

Should a function declaration without the type of its parameters compile in ANSI C?

I'm investigating ANSI C. Should this compile? Could this code comply with a newer standard? (It tried but always got the error) #include #include float declaration(); float prototype(float); int main(void) { …
Plouff
  • 3,290
  • 2
  • 27
  • 45
4
votes
4 answers

Does continous reassigning of character strings lead to memory leak?

I have two questions: Q1. The character pointers are used to point to a location where a given string is stored. If we keep reassigning the string, does it lead to memory leak? On a Linux system I see: $ cat chk.c #include #define VP…
Quiescent
  • 1,088
  • 7
  • 18
4
votes
1 answer

Redirect stdout to file without ANSI warnings

I've been trying to get a program's STDOUT redirecting to a file. So far, this code works well: FILE *output = fopen("output","w"); if (dup2(fileno(output),1) == -1) { /* An error occured. */ exit(EXIT_FAILURE); } The issue is, I'm trying…
Darcy Rayner
  • 3,385
  • 1
  • 23
  • 15
4
votes
1 answer

IOCCC 1988/isaak.c - why no output even after ANSIfication?

The carefully crafted, self-including code in this IOCCC winning entry from 1988: http://www.ioccc.org/years.html#1988_isaak ...was still too much for certain systems back then. Also, ANSI C was finally emerging as a stable alternative to the…
4
votes
1 answer

AddressSanitizer: heap-use-after-free ANSI C

I am getting this error when I try to clear a linked list ================================================================= ==4574==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000000050 at pc 0x7fcb73b40682 bp 0x7ffffcfd8370 sp…
lorenuar
  • 41
  • 1
  • 2
4
votes
4 answers

Type checking arbitrary length array in ANSI C

Hi I am confined to stdio.h, stdlib.h and string.h and I need to ask a user for input - the input can be any number of characters between 1 and 6, however the first two characters MUST be an uppercase alphabetical letter, and the remaining four…
Davide Lorino
  • 875
  • 1
  • 9
  • 27