Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors within standard header files

Tags:

c++

c

syntax

header

I'm currently getting the following errors:

c:\program files\microsoft visual studio\vc98\include\iomanip(15) : error C2059: >syntax error : 'namespace'

c:\program files\microsoft visual studio\vc98\include\iomanip(15) : error C2334: >unexpected token(s) preceding '{'; skipping apparent function body

c:\program files\microsoft visual studio\vc98\include\math.h(36) : error C2059: syntax >error : 'string'

c:\program files\microsoft visual studio\vc98\include\math.h(36) : error C2334: unexpected >token(s) preceding '{'; skipping apparent function body

As they are all in the standard library header files, and therefore read only, I don't know how to fix it!

Any help would be great.

like image 456
bemused and confused Avatar asked Apr 26 '12 12:04

bemused and confused


2 Answers

In C/C++, the preprocessor runs before the source code is actually parsed, and #includes basically just splice together different files. One consequence of this is that C/C++ are perfectly happy with having a { in one file match a } in another (included) file. Of course, no one ever does this (or if they do, they should be shot), but because the C/C++ preprocessor is so simple-minded, it's technically allowed.

One consequence of this is that a syntax error in one of your own files can end up looking like a syntax error in some other file. I most often encounter this myself when I forget to put a ; after a class definition. But mismatched {}s can (as you discovered) have the same effect.

So if you ever see an error in some included file that you think probably shouldn't be there (eg a standard library), then the first place to look is whatever file was included just before that file. Sometimes rearranging your #include statements can help narrow down the source of the error as well.

like image 61
Edward Loper Avatar answered Oct 12 '22 22:10

Edward Loper


Visual Studio:

  1. Open the project's Property Pages dialog box.
  2. Click the C/C++ folder.
  3. Click the Advanced property page.
  4. Show Includes (Yes)

Build the project, in the build output you should see the include tree. Find the first occurrence of the error, and scan upwards opening each include file (that you wrote) to find which one has the missing curly bracket "}"

like image 32
Lefteris Eleftheriades Avatar answered Oct 12 '22 23:10

Lefteris Eleftheriades