RSS Forums RSS

for loop as a macros

Please support our C++ advertiser: Programming Forums
Reply
Posts: 4
Reputation: aryansmit3754 is an unknown quantity at this point 
Solved Threads: 0
aryansmit3754 aryansmit3754 is offline Offline
Newbie Poster

for loop as a macros

  #1  
Jan 3rd, 2009
could somebody tell wats wrong with this
#define FOR(x,n)for(typeof(x);x<n;x++)
AddThis Social Bookmark Button
Reply With Quote  
Posts: 717
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 80
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Master Poster

Re: for loop as a macros

  #2  
Jan 3rd, 2009
Just don't use macros for loops.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote  
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 29
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: for loop as a macros

  #3  
Jan 3rd, 2009
Firstly, there is no space between the closing bracket at the end of FOR(x,n) and preceding the rest. That's a stylistic concern, but badly hurts readability.

Second, and more significantly, typeof() is not a standard function or operator in C++. It is an extension specific to g++ (GNU c++) in which typeof(x) expands to be type of x and will trigger a compiler error with every compiler that does not support that extension. Within a for loop (assuming you're using g++), if x is an int, then FOR(x,n) would expand to for (int; x < n; x++) which is invalid code.
Reply With Quote  
Posts: 2,000
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 331
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: for loop as a macros

  #4  
Jan 3rd, 2009
Apart from anything else this useless macros must be
  1. #define FOR(x,n)for(typeof(x)x=0;x<(n);x++)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 431 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:40 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC