Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Acrinis True image 2 58
Close word object 13 38
ASP.NET 5 Templates 2 66
Error creating a new C++ project in ,net 20 21
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 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

21 Experts available now in Live!

Get 1:1 Help Now