Fatal Error C1019. No error if it is compiled in VC++ 6.0

G

Guest

Hi,

I have a C++ source file (mymessage.cpp), it is used by two different
platforms. PC and VxWorks.

The file has a header section to include header files depending on which
platform it is compiled. The code is like this:

#ifndef _VxWORKS
#include "stdafx.h"
#include "PCclass.h"
#else // Error pointed line
#include "noPCclass.h"
#endif

.....

where stdafx.h is a precompiled header file on PC side. PCclass.h is the
header file needs to be included in PC side, and noPCclass.h is the header
file needs to be included in VxWorks side.

When I compile this file mymessage.cpp in Visual C++ .Net, I got compile
error C1019. But the same file is compiled in Visual C++ 6.0, and I got no
error.

I did some investigation, I found that actually, the error is caused by
precompiled header file stdafx.h. If I move #incldue "stdafx.h" outside of
#idndef, #else block. like following,


#include "stdafx.h"

#ifndef _VxWORKS
#include "PCclass.h"
#else
#include "noPCclass.h"
#endif

then error goes away. But that means I need to put stdafx.h in VxWorks
enviroment. I don't want to do this, since stdafx.h is Microsoft stuff.
Any one has any better solution?

Thanks,
 
L

Larry Brasfield

Cynthia said:
Hi, Hi.

I have a C++ source file (mymessage.cpp), it is used by two different
platforms. PC and VxWorks.

The file has a header section to include header files depending on which
platform it is compiled. The code is like this:

#ifndef _VxWORKS
#include "stdafx.h"
#include "PCclass.h"
#else // Error pointed line
#include "noPCclass.h"
#endif

....

where stdafx.h is a precompiled header file on PC side. PCclass.h is the
header file needs to be included in PC side, and noPCclass.h is the header
file needs to be included in VxWorks side.

When I compile this file mymessage.cpp in Visual C++ .Net, I got compile
error C1019. But the same file is compiled in Visual C++ 6.0, and I got no
error.

That was (good or bad) luck, I think.
I did some investigation, I found that actually, the error is caused by
precompiled header file stdafx.h.

More accurately, it was caused by imbalanced preprocessor
directives that result from how precompilation is effected.
You would see the same effect regardless of the content
of stdafx.h.
If I move #incldue "stdafx.h" outside of
#idndef, #else block. like following,


#include "stdafx.h"

#ifndef _VxWORKS
#include "PCclass.h"
#else
#include "noPCclass.h"
#endif

then error goes away. But that means I need to put stdafx.h in VxWorks
enviroment. I don't want to do this, since stdafx.h is Microsoft stuff.
Any one has any better solution?

There is nothing magic about the name "stdafx.h" other than
certain Microsoft tool wizards having picked it for you.

One improvement on the situation would be to put the
conditional compilation directives within stdafx.h itself,
making it do nothing (or whatever you like in the way
of a standard #include sequence) for non-VC builds.
And if you dislike the name stdafx.h, you are free to
change it. Perhaps "std_incs.h", indicating that it is
not dedicated to the VC build or AFX stuff.
You're welcome.
 

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

Top