A structure question.

  • Thread starter Vijay Kumar R Zanvar
  • Start date
V

Vijay Kumar R Zanvar

Hi,
Have a look at the following program:

//++

/* struct.cpp */
#include <stdio.h>

struct {
int a;
int b;
struct {
int c;
};
}a = { 10, 12, 14};

int
main ()
{
printf ( "sizeof a = %d\n", sizeof a );
printf ( "a.a: %d a.b: %d a.c: %d\n", a.a, a.b. a.c );
return 0;
}

//--

I compiled the program using:

# g++ struct.cpp -ansi -Wall
# ./a.out
12
a.a: 10 a.b: 12 a.c: 14

OK. The program worked in Linux.

Turbo C++ 3.0 / WinNT gave the following errors:
* To many initializers
* Structure required on left side of . or .*

The -ansi option confirms ANSI compliance. Then why Turbo C++
flagged the errors?

By the way... what are applications of declaring structures
as above?

Thanks.
 
P

Peter van Merkerk

The -ansi option confirms ANSI compliance. Then why Turbo C++
flagged the errors?

Turbo C++ 3.0 is a very ancient compiler, which was introduced long
before C++ was standardized. Consequently it is not standard compliant
(far from it), and the -ansi option probably means that the compiler
will be compiliant with ANSI C 1989, not ANSI C++.

I recommend you look for a more up to date compiler. There are several
free compilers available. Most, if not all, of those compilers are a lot
closer to the C++ standard than Turbo C++. The latest versions of GCC
are getting close to fully compliant with the C++ standard. For a fully
compliant compiler look at: http://www.comeaucomputing.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top