3

I need to confirm my code if I'm using ANSI C (C89/C90) and I notice this:

enter image description here

Even if I have selected ASNI C (C89/C90) standard in Eclipse CDT.

enter image description here

Question:

It is told that ANSI C does not use __STDC_VERSION__ but why do I see the same value for __STDC_VERSION__ as 199901L for C99 standard in Eclipse CDT?

I'm using GCC compiler for Lubuntu Linux.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
euraad
  • 2,467
  • 5
  • 30
  • 51
  • *This macro expands to the C Standard's version number, a long integer constant of the form yyyymmL where yyyy and mm are the year and month of the Standard version. This signifies which version of the C Standard the compiler conforms to. Like __STDC__, this is not necessarily accurate for the entire implementation, unless GNU CPP is being used with GCC. The value 199409L signifies the 1989 C standard as amended in 1994, which is the current default; the value 199901L signifies the 1999 revision of the C standard.* – 0___________ Feb 27 '23 at 23:31
  • @0___________ and why does STDC version show 199901L when I selected C89? – euraad Feb 27 '23 at 23:38
  • The `__STDC_VERSION__` macro was added to C94 (Amendment 1); it was not part of C89/C90, so it won't be set by a compiler that faithfully follows the C89/C90 standard. There's no good reason to be using C89/C90 these days. You should be using C11 or C18 (C17). – Jonathan Leffler Feb 27 '23 at 23:58
  • 1
    @JonathanLeffler I understand, but I'm not using C99 standard I'm using C89/C90 standard as you see. – euraad Feb 28 '23 at 00:01
  • @euraad Although this does not answer your question, have you tried with the `-traditional` flag? – Marco Feb 28 '23 at 00:08
  • It's hard for me to guess what Eclipse CDT is doing — I don't have it installed anywhere. At the command line, on my Mac, using `-std=c90` causes the compilation to fail because there are C++-style comments in ``. On a Linux machine, I got zero as the output from: `#include ` / `int main(void) {` / `#ifndef __STDC_VERSION__` / `#define __STDC_VERSION__ 0L` / `#endif` / `printf("%ld\n", __STDC_VERSION__); return 0; }` (file `stdc13.c` compiled using `gcc -std=c90 -o stdc13 stdcs13.c`). Have you compiled and run the code? Is the GUI misleading you? – Jonathan Leffler Feb 28 '23 at 00:08
  • @JonathanLeffler it might be a bug in Eclipse CDT? – euraad Feb 28 '23 at 00:19
  • Yes, it might be a bug (feature?) in Eclipse CDT. – Jonathan Leffler Feb 28 '23 at 00:33

1 Answers1

2

I have tested it. Eclipse CDT simply shows the oldest value programmed. It does not have anything in common with the actual __STDC_VALUE__ seen by the compiler.

When you compile as C90 __STDC_VALUE__ is not defined and value shown in the Eclipse is not valid. I believe that it is an Eclipse bug.

Colouring is also wrong.

enter image description here

0___________
  • 60,014
  • 4
  • 34
  • 74
  • Yes! It's a bug in Eclipse! The code is working. But the GUI is missleadning. Thank you for your answer. – euraad Feb 28 '23 at 19:40