LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-08-2006, 06:33 PM   #1
karan101
Member
 
Registered: Aug 2004
Location: CANADA
Distribution: Fedora core4
Posts: 60

Rep: Reputation: 15
c++ compilation


I get this compilation error when i try to compile this line code under g++ 4.0.1 :

Code:
analyze.cpp: In member function ‘void Analyzer::incScope(TreeNode*)’:
analyze.cpp:321: error: cast from ‘TreeNode*’ to ‘int’ loses precision
and my code is this:

Code:
symobTable->incScope( int(t));
t is tree node which looks like this:

Code:
class TreeNode {
public:

static const int MAXCHILDREN = 3;
TreeNode * child[MAXCHILDREN];
TreeNode * sibling;
int lineno;
NodeKind nodekind;
union {
DeclKind decl;
StmtKind stmt;
ExpKind exp;
} kind;

union {
TokenType op;
int val;
char * name;
} attr;

ExpType type;

int scope;
};
this code compiles under g++ 2.95 but not with 4.01 anybody knows what kind of casting I should be using or any way to get around this...
thanks

Last edited by karan101; 03-08-2006 at 07:17 PM.
 
Old 03-08-2006, 07:11 PM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Firstly, post you code in code tags instead of quote tags (please edit your post). Secondly, [i]don't[i] add any characters to your code or the compiler output. Be verbatim! (edit that out too).

I assume you have added stars in pairs (baaad idea--use italics, bold or something similar to emphasize stuff you think it's needed).

So that raises the question: why do you want to cast the node to an int? What you might mean is to take the address of t (one spells that "&t").

hth --Jonas
 
Old 03-09-2006, 04:02 AM   #3
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
I didn't get it. If the function takes TreeNode as the parameter and the parameter you are passing is also TreeNode, then why you are casting that variable to int???
Just pass the variable 't' into the function, i don't think you should cast it.
 
Old 03-09-2006, 10:38 AM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
cppkid: actually, we're both wrong--you thought it was (TreeNode, TreeNode), I thought it was (TreeNode, TreeNode*). In fact (read the OP), it's (TreeNode*, TreeNode*).

To OP: don't cast it to an int. Just pass in t.
 
Old 03-09-2006, 10:59 AM   #5
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
Yes i noticed that, i just just wanted to put your attention that you didn't have to cast to someother datastructure... Anyway my fault that i didn't mentioned properly... Sorry for inconvinence...

All the best.
 
Old 03-09-2006, 11:02 AM   #6
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
np. I just wanted to point it out so the OP didn't get more confused than necessary.
 
Old 03-12-2006, 05:23 AM   #7
karan101
Member
 
Registered: Aug 2004
Location: CANADA
Distribution: Fedora core4
Posts: 60

Original Poster
Rep: Reputation: 15
thnx guys for the commens. I don't understand it myself why the author is casting that. Its just a complicated c code that we have to modify it for our project.... I tryed to understand it but its just to messy anyways the interesting thing is that it compiles at school with g++ 2.95 but not on my laptop's 4.01 ... is there anything i can do to compile it without changing the code...
thanks
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
compilation? itz2000 Programming 19 11-11-2005 02:25 PM
Compilation arunachalam Linux - General 3 11-10-2005 05:11 PM
Qt compilation nitin_kataria Programming 1 10-13-2003 04:33 PM
Compilation HoRrIdPrObLeMs Programming 2 03-12-2002 02:52 PM
Compilation mikeshn Programming 2 03-03-2002 10:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration