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:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 17th, 2003, 04:24 AM
lutkebab lutkebab is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 lutkebab User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Visual Studio 7

Hi!

Why does this code not work?



const int INTSIZE = sizeof(int); //sizeof(int) = 4

#if (INTSIZE!=4)
//do something
#endif



INTSIZE is 0!!! in the #if statment above, why??

Reply With Quote
  #2  
Old February 17th, 2003, 12:36 PM
3dfxMM 3dfxMM is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 266 3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 19 h 1 m 34 sec
Reputation Power: 12
INTSIZE is an integer variable that will only exist when the code is running. #if is a compile time only test. Since INTSIZE has no value at compile time, it will evaluate to zero. If you really want to do a one time capture of sizeof(int) you can try this instead:

#define INTSIZE (sizeof(int))

Then your #if will work.

Reply With Quote
  #3  
Old February 23rd, 2003, 12:16 PM
ahuimanu ahuimanu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Right Coast
Posts: 25 ahuimanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 34 sec
Reputation Power: 0
The "#" is for conditional compilation, so just test with a normal if

if( INT_SIZE !+ 4){

//do stuff

}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Visual Studio 7


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway