Solved

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

Posted on 2014-11-12
5
657 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 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 40436853
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
ID: 40436856
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
ID: 40436867
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 31

Expert Comment

by:Zoppo
ID: 40436870
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 31

Expert Comment

by:Zoppo
ID: 40436877
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

808 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