-4

I know there are some difference between ANSI C 89 and C that supports by C++.

for example in ANSI C 89, you should declare variables at first line of blocks.

or when you want to declare struct variables, you should use struct keyword (eg struct student std1;).

or // is not valid for commenting and you should use /**/ for commenting in ANSI C 89.

for example this C code is not valid in ANSI C 89:

struct student
{
  char* name;
};

enum number
{
  ODD,
  EVEN
};

void test()
{
  printf("Hello world!");
  int a, b; // Not valid in ANSI C 89, variables should declare at first line of blocks.
  student std1; // Not valid. It should be: struct student std1;
  struct student std2; // Valid.
  number n1 = ODD; // Not valid.
  enum number n2 = EVEN; // Valid.
}

I want to develope an application using ANSI C 89 and my question is:

What is the difference between ANSI C 89 and C that supports by C++?

Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
  • are you talking about C99? http://en.wikipedia.org/wiki/C99 – Karoly Horvath Sep 26 '11 at 11:30
  • What do you mean by "C that supports by C++"? Are you talking about C99? Most compilers, even ones that support C99, will let you switch on "strict ANSI" options to warn or error in case of non-ANSI constructs being used. – Vicky Sep 26 '11 at 11:30
  • What is "C that supports by C++"? C++ is a different language which has C as subset, but introduces many changes and differences. – glglgl Sep 26 '11 at 11:31
  • @yi_H: No! I want to use ANSI C 89, because C99 is not supported by some comiplers (for example MS VC++). – Amir Saniyan Sep 26 '11 at 11:32
  • 1
    There's no such thing as "C that is supported by C++". C++ is a language. C is another language. C++ permits a lot of things that are permitted in C89 -- most of them in fact. But there are loads of things that C++ allows and C doesn't not - keyword `class` for example, and `std::vector`. The C++ standard is much longer than the C standard, answers here cannot possibly list all the differences. Just learn C89 from a book such as K&R. – Steve Jessop Sep 26 '11 at 11:32
  • @glglgl: C++ supports C. I mean C subset of C++. – Amir Saniyan Sep 26 '11 at 11:33
  • Oh yes, you're right. Stupid me. Deleted. – Fred Foo Sep 26 '11 at 11:40

1 Answers1

4

The C subset of C++98/03 is modeled on C89 (obviously, since C99 wasn't out at the time); that of C++11 is modeled on C99. Nonetheless, the languages are quite different and the C subset of C++ isn't the same as the language C.

You're essentially asking "what's the difference between C++ and C", which isn't really a suitable question.

(For example, sizeof('a') is different in C and in C++, so if you're using MSVC++, knowing the C standard on which C++ was modeled doesn't help you at all).

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • 1
    +1 for "the C subset of C++ isn't the same as the language C." Ain't it the truth. – Pete Wilson Sep 26 '11 at 11:41
  • *You're essentially asking "what's the difference between C++ and C", which isn't really a suitable question.* - this means that your answer should be really a comment and the question should be closed, no? – BЈовић Sep 26 '11 at 11:43