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
11
votes
3 answers

Why does my C++0x code fail to compile if I include the "-ansi" compiler option?

I've come across a really weird error that only pops up if I use the ansi flag. #include class Test { public: explicit Test(std::shared_ptr ptr) {} }; Here's the compilation, tested with gcc 4.5.2 and 4.6.0 (20101127): g++…
anon
  • 121
  • 4
11
votes
2 answers

C11 Standard docs

Starting from this SO protected question I'm trying to understand what the difference between those documents: 9899 2012 costs $60 9899 2011 costs $265 As you can see those documents have very different prices and I don't know if the cheaper one…
LPs
  • 16,045
  • 8
  • 30
  • 61
11
votes
2 answers

Initializing bit-fields

When you write struct { unsigned a:3, b:2; } x = {10, 11}; is x.b guaranteed to be 3 by ANSI C (C89)? I have read and reread the standard, but can't seem to find exactly that case. For example, "result that cannot be represented by…
Veky
  • 2,646
  • 1
  • 21
  • 30
10
votes
1 answer

string array initialisation

This is a continuation of another question I have. Consider the following code: char *hi = "hello"; char *array1[3] = { hi, "world", "there." }; It doesn't compile to my surprise (apparently I don't know C syntax as well as I thought)…
lang2
  • 11,433
  • 18
  • 83
  • 133
9
votes
3 answers

Interface/Implementation in ANSI C

I'm working on a large project in C, and I want to organize it using interface (.h) and implementation (.c) files, similar to many object-oriented languages such as Objective-C or Java. I am familiar with creating static libraries in C, but I think…
user2105505
  • 686
  • 1
  • 9
  • 18
8
votes
4 answers

string array conversion

I have the following code: char *array1[3] = { "hello", "world", "there." }; struct locator_t { char **t; int len; } locator[2] = { { array1, 10 } }; It compiles OK with "gcc -Wall -ansi -pedantic". But…
lang2
  • 11,433
  • 18
  • 83
  • 133
8
votes
1 answer

Verifying ctypes type precision in Python

If an API expects a 64 bit type, how can I check that a ctypes type has that many bits if sizeof returns the number of bytes? How do I know how many bits are in each byte on the current platform? Where is CHAR_BIT defined in Python?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
8
votes
4 answers

What is the behavior of C89 with respect to integer division of two negative numbers: round up, round down or not defined?

For Example, If I write int var; var=-8/-5; As per operator precedence, -8/-5 would be equivalent to ((-8)/(-5)). But will it be possible for C89 to give two values like for the case of -8/5 it can give -1 or -2. or It will treat it as the division…
8
votes
2 answers

atof() for float instead of double

atof() returns a double, which results in a warning when I assign it to a float-value (and yes, I definitively have to use float). So my question: is there a atof()-variant available which returns a plain float? Or do I have to solve this by a cast…
Elmi
  • 5,899
  • 15
  • 72
  • 143
7
votes
2 answers

Why won't this code compile and run in Visual Studio 2010?

I am trying to get Visual Studio 2010 set up to do plain old ANSI compilation, without Microsoft extensions of any kind. I started with an empty project template, since there doesn't seem to be a plain ANSI project template in 2010 anymore. Then I…
user177800
7
votes
2 answers

Are there any well-established/standardized ways to use fixed-width integers in C89?

Some background: the header stdint.h is part of the C standard since C99. It includes typedefs that are ensured to be 8, 16, 32, and 64-bit long integers, both signed and unsigned. This header is not part of the C89 standard, though, and I haven't…
Lehonti
  • 133
  • 8
7
votes
2 answers

Iterate through char array and print chars

I am trying to print each char in a variable. I can print the ANSI char number by changing to this printf("Value: %d\n", d[i]); but am failing to actually print the string character itself. What I am doing wrong here? #include #include…
ojhawkins
  • 3,200
  • 15
  • 50
  • 67
6
votes
4 answers

Multiple const in one variable declaration

A colleague of mine is going a bit nuts with const in ANSI C and I wanted to know what you guys thought about it. He writes stuff like this for example: const uint8* const pt_data I understand where he's going with this but for me it makes the…
Leo
  • 500
  • 5
  • 15
6
votes
2 answers

C++ standards, am a little confused?

I am aware the standard was ratified in 1998, and an update to repair some defects in the standard took place in 2003 (the ISO standards) although I am unsure of the relation of C++98 and the ANSI C standards. I remember more than once reading the…
Den R.
  • 135
  • 6
6
votes
3 answers

Setting Visual C++ Studio/Express to strict ANSI mode

I generally program & compile under Linux with gcc and -ansi flag; but I've been forced with doing a job in Visual C++ and whenever I compile my C code I get all the Microsoft warnings like 'fscanf': This function or variable may be unsafe.…
jparanich
  • 8,372
  • 4
  • 26
  • 34
1 2
3
41 42