C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 30th, 2009, 12:11 PM
wbest wbest is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 55 wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 25 m 7 sec
Reputation Power: 19
Bizzare Errors in C++ code (g++)

Hey, I've got some C++ code that I have to maintain on Linux, it was originally written in Windows, but I have to port it to Linux.

Anyway, I'm attempting to compile it, but I'm getting very strange errors:

include/zone.h:33: error: expected ‘;’ before ‘&’ token
include/zone.h:33: error: expected `;' before ‘protected’
include/zone.h:33: error: expected ‘;’ before ‘&’ token
include/zone.h:33: error: expected `;' before ‘XString’
include/zone.h:33: error: expected ‘;’ before ‘&’ token
include/zone.h:33: error: expected `;' before ‘private’
include/zone.h:33: error: ‘XString’ does not name a type
include/zone.h:34: error: expected ‘;’ before ‘&’ token
include/zone.h:34: error: expected `;' before ‘protected’
include/zone.h:34: error: expected ‘;’ before ‘&’ token
include/zone.h:34: error: expected `;' before ‘XString’
include/zone.h:34: error: expected ‘;’ before ‘&’ token
include/zone.h:34: error: expected `;' before ‘private’
include/zone.h:34: error: ‘XString’ does not name a type
include/zone.h:102: error: ‘XString’ does not name a type
include/zone.h:103: error: ‘XString’ does not name a type


The corresponding code is (lines 27-37, the one with TimeZoneName is lin 33):

class CORE_API XZone
#ifdef USE_COMPAT
: public XCompatZone
#endif
{
X_PROTECTED(bool, DaylightObserved); // daylightObserved_
X_PROTECTED(XString, TimeZoneName); // seconds west of UTC: timeZoneName_
X_PROTECTED(XString, AltZoneName); // altZoneName_
X_PROTECTED(int, TimeZoneOffset); // timeZoneOffset_
X_PROTECTED(int, AltZoneOffset); // altZoneOffset_
X_PROTECTED_CONST_PTR(XDaylightRule, DaylightRule); // rule_



What is X_PROTECTED, you ask?

#define X_PROTECTED(T,A) \
public: \
const T& A() const { return pv_##A; } \
protected: \
T& ref_##A() { return pv_##A; } \
T& A(REF_PARAM) { return pv_##A; } \
private: \
T pv_##A;

Reply With Quote
  #2  
Old June 30th, 2009, 12:24 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 795 L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 33 m 41 sec
Reputation Power: 233
Send a message via AIM to L7Sqr
Does the line:
Quote:
Originally Posted by error messages
include/zone.h:33: error: ‘XString’ does not name a type
not help you?
__________________
Some people have 20 years of experience. Some have 1 year of experience 20 times.

My personal site: Basic geek randomness

Reply With Quote
  #3  
Old June 30th, 2009, 12:39 PM
wbest wbest is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 55 wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 25 m 7 sec
Reputation Power: 19
Quote:
Originally Posted by L7Sqr
Does the line:
not help you?


Well, see, that error comes after the weird errors with the semicolon.
So I was assuming that even if I fixed the X_STRING error, I'd still have those semicolon errors.

Do you think this thought process is wrong?

Also, is X_STRING part of a windows library? I can't find much about it online.

Reply With Quote
  #4  
Old June 30th, 2009, 01:39 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 795 L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 33 m 41 sec
Reputation Power: 233
Send a message via AIM to L7Sqr
Code:
#define X_PROTECTED(T,A) \
   public: \
      const T& A() const { return pv_##A; } \
   protected: \
      T& ref_##A() { return pv_##A; } \
      T& A(REF_PARAM) { return pv_##A; } \
   private: \
      T pv_##A;

Given the above, X_PROTECTED(XString, TimeZoneName); expands (roughly) into:
Code:
   public: 
      const XString& TimeZoneName() const { return pv_TimeZoneName; } 
   protected:
      XString& ref_TimeZoneName() { return pv_TimeZoneName; }
      XString& TimeZoneName(REF_PARAM) { return pv_TimeZoneName; }
   private:
      XString pv_TimeZoneName;

Suppose I try to compile that
Code:
#include <iostream>

using namespace std;

class Foo {
   public: 
      const XString& TimeZoneName() const { return pv_TimeZoneName; } 
   protected:
      XString& ref_TimeZoneName() { return pv_TimeZoneName; }
      XString& TimeZoneName(REF_PARAM) { return pv_TimeZoneName; }
   private:
      XString pv_TimeZoneName;
};

int main () {
        Foo f;
        return 0;
}

I get
Quote:
Originally Posted by error slop
x.cpp:7: error: ISO C++ forbids declaration of `XString' with no type
x.cpp:7: error: expected `;' before '&' token
x.cpp:8: error: expected `;' before "protected"
x.cpp:9: error: ISO C++ forbids declaration of `XString' with no type
x.cpp:9: error: expected `;' before '&' token
x.cpp:10: error: expected `;' before "XString"
x.cpp:10: error: ISO C++ forbids declaration of `XString' with no type
x.cpp:10: error: expected `;' before '&' token
x.cpp:11: error: expected `;' before "private"
x.cpp:12: error: `XString' does not name a type

And if I use a macro:
Quote:
Originally Posted by macro error slop
x.cpp:15: error: ISO C++ forbids declaration of `XString' with no type
x.cpp:15: error: expected `;' before '&' token
x.cpp:15: error: expected `;' before "protected"
x.cpp:15: error: ISO C++ forbids declaration of `XString' with no type
x.cpp:15: error: expected `;' before '&' token
x.cpp:15: error: expected `;' before "XString"
x.cpp:15: error: ISO C++ forbids declaration of `XString' with no type
x.cpp:15: error: expected `;' before '&' token
x.cpp:15: error: expected `;' before "private"
x.cpp:15: error: `XString' does not name a type

Notice the change in line number information. And, since you mention that the line with TimeZoneName is 33 I can only assume that this is your error.

Reply With Quote
  #5  
Old June 30th, 2009, 01:52 PM
wbest wbest is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 55 wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level)wbest User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 25 m 7 sec
Reputation Power: 19
Quote:
Originally Posted by L7Sqr
Notice the change in line number information. And, since you mention that the line with TimeZoneName is 33 I can only assume that this is your error.


I see. What macro are you using? I'm a little confused by that.

Anyway, just to clarify, you still think (with supporting examples) that my errors are coming from XString not being defined, and that the real error I'm getting is from another header file (X_PROTECTED is defined elsewhere, in the spirit of full disclosure). I think I've seen that problem before.

So I'll try to find where I can define XString or get XString defined or whatever.

I may be back later...

Reply With Quote
  #6  
Old June 30th, 2009, 02:18 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 795 L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level)L7Sqr User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 33 m 41 sec
Reputation Power: 233
Send a message via AIM to L7Sqr
Quote:
Originally Posted by wbest
you still think (with supporting examples) that
I think you had a copy/paste error in your initial post (leaving out the first XString message).

My comment (and example) about the macro is that the text is expanded into a single line; hence all the line 33 errors in your output (or line 15 in mine).

Quote:
Originally Posted by wbest
X_PROTECTED is defined elsewhere, in the spirit of full disclosure
I dont care where it is defined, it is expanded where you use it.

Reply With Quote
  #7  
Old July 1st, 2009, 05:25 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 3,712 clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level)clifford User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 23 h 23 m 3 sec
Reputation Power: 1165
You have just discovered why macros are a bad idea!

Reply With Quote
  #8  
Old July 1st, 2009, 06:26 AM
LittleGrin LittleGrin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 378 LittleGrin User rank is Captain (20000 - 30000 Reputation Level)LittleGrin User rank is Captain (20000 - 30000 Reputation Level)LittleGrin User rank is Captain (20000 - 30000 Reputation Level)LittleGrin User rank is Captain (20000 - 30000 Reputation Level)LittleGrin User rank is Captain (20000 - 30000 Reputation Level)LittleGrin User rank is Captain (20000 - 30000 Reputation Level)LittleGrin User rank is Captain (20000 - 30000 Reputation Level)LittleGrin User rank is Captain (20000 - 30000 Reputation Level)LittleGrin User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 2 h 2 m 27 sec
Reputation Power: 259
Quote:
Originally Posted by clifford
You have just discovered why macros are a bad idea!

Maybe so.

However, the reason the code fails to compile is that it declares functions returning reference to XString, but no XString type is declared. Trying to return a reference to an unknown type is the reason the compiler complains about expecting something before an & token. The wording of the error message may not be all that clear, but compilers are only required to diagnose errors - they are not necessarily required to diagnose errors in an intuitive manner.

Presumably, there is a header file that declares XString somewhere which needs to be #include'd before using the X_PROTECTED macro.
Comments on this post
clifford agrees: Of course. I was referring to the way in which compiler messages refer to the expansion, not the
original source, so it is often hard to fathom the "bizarre errors", which is the OP's primary
complaint.
__________________
Right 98% of the time, and don't care about the other 3%.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Bizzare Errors in C++ code (g++)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
Stay green...Green IT