Solved

C++ compiler error C2628: 'int8_t' followed by 'bool' is illegal (did you forget a ';'?)

Posted on 2014-11-12
5
584 Views
Last Modified: 2014-11-12
I'm trying to compile the code found on this sourceforge site http://sourceforge.net/projects/bacnet/files/bacnet-stack/, under the ports/Win32/VS2010 folder so I can integrate into a .NET application.

When trying to compile I get and error as in the title of this question. The source file in error is below:

#ifndef _STDBOOL_H
#define _STDBOOL_H

#include <stdint.h>

/* C99 Boolean types for compilers without C99 support */
/* http://www.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html */
#if !defined(__cplusplus)

#if !defined(__GNUC__)
/* _Bool builtin type is included in GCC */
/* ISO C Standard: 5.2.5 An object declared as 
   type _Bool is large enough to store 
   the values 0 and 1. */
/* We choose 8 bit to match C++ */
/* It must also promote to integer */
typedef int8_t _Bool;
#endif

/* ISO C Standard: 7.16 Boolean type */
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1

#endif

#endif

Open in new window

0
Comment
Question by:wint100
  • 3
  • 2
5 Comments
 
LVL 30

Accepted Solution

by:
Zoppo earned 500 total points
Comment Utility
Hi wint100,

the code is only used to add bool type to compilers where it's not a built-in type like C-compilers before C99.

What compiler do you use? If you use a C++ compiler this code shouldn't be compiled at all coz '__cplusplus' is defined. This is because in C++ the bool is a built-in type. The code which fails to build is only intended to be built with a C-compiler.

If you compile it with a C99 compliant C compiler which has built-in bool which is not GCC (for which a comaprsione is there) you have to either change or simply remove the code.

Hope that helps,

ZOPPO
0
 
LVL 1

Author Comment

by:wint100
Comment Utility
Hi,

I'm using Visual studio 2013 to compile this. Maybe this is a C build and I need to look at changing the compiler, any idea how this is done, I'm only used to using C# .NET applications.

Thanks
0
 
LVL 1

Author Comment

by:wint100
Comment Utility
Ah, got it to compile by simply commenting out that part of the code:

//#if !defined(__GNUC__)
///* _Bool builtin type is included in GCC */
///* ISO C Standard: 5.2.5 An object declared as 
//   type _Bool is large enough to store 
//   the values 0 and 1. */
///* We choose 8 bit to match C++ */
///* It must also promote to integer */
//typedef int8_t _Bool;
//#endif

Open in new window

0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
Hi,

first check the extension of the source file - VisualStudio per default uses a C compiler for all *.c files and a C++ compiler for *.cpp, *.c++, *.cc, ...

If it is not a *.c file which includes the posted code you have to check the file's compile settings, it is possible to tell VisualStudio per file which compiler is used.

ZOPPO
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
Sorry, the last comment seems to be wrong: I wasn't able to find option to i.e. tell VisualStudio (I use 2010) to build a *.c file with a C++ compiler - I'm think previous VisualStudio versions had this, but it seem it's either vanished or I simply can't find ...
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now