Solved

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

Posted on 2014-11-12
5
718 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 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.

617 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