![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Jan 2002
Posts: 1
| Note: this is just an example. The actual code I'm working with is much, much messier. example: IF ( validnumber(i) ) { /* outer code block */ { /* inner code block */ /* do something in here */ } } The inner code block is surrounded by { } but it doesn't follow a conditional statement, or function name. Does anyone know whether the program will move from the outer code block into the inner code block and then out again back to the outer code block? Or will the compiler complain? The reason I ask is that I'm working with some code that uses a lot of macro string substitution, and in some cases code blocks may or may not end up with leading IF conditions statements after the preprocessor is done with it. Please help. |
| albertr is offline | |
| | #2 |
| Registered User Join Date: Sep 2001
Posts: 752
| Don't worry, in cases like that, it will just work the same as if the inner braces weren't there.
__________________ Callou collei we'll code the way Of prime numbers and pings! |
| QuestionC is offline | |
| | #3 |
| Registered User Join Date: Dec 2001
Posts: 44
| Consider: if (cond) something; and... if (cond) { something; } Both of these do the same thing... just to make it a bit clearer what's happening here...(items closed in <>'s are placeholders for what is described). If statements take the following form: if ( <condition_expression> ) <statement> (in reality, it's a little more complex than this, but this serves to get the point across). A statement can be a simple statement (like an expression terminated by a semi-colon), or a compound statement amongst other things. A compound statement inside another compound statement (say, in a function) behaves exactly the same as everywhere else - as the statement used in an if or while statement, as the compound statement in a function definition and so on. There's nothing special about compound statements... they're the same everywhere! Ian Woods |
| hairyian is offline | |
| | #4 | |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,260
| Quote:
Code: #include <stdio.h>
int main ( void )
{
int x;
printf("x is visible\n");
{
int y;
printf("x and y are visible\n");
{
int z;
print("x, y and z are visible\n");
}
printf("x and y are visible\n");
}
printf("x is visible\n");
return 0;
}
Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? | |
| quzah is offline | |
| | #5 |
| Linguistic Engineer... Join Date: Aug 2001 Location: CA
Posts: 2,420
| limiting scope is important, and using braces correctly can help you control scope very well. however make sure that in your macro's scope, you don't declare varible names that you'd have in the mother scope, as your compiler would then be confused perhaps.
__________________ hasafraggin shizigishin oppashigger... |
| doubleanti is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| backward debugging in Visual Studio?? | George2 | Tech Board | 12 | 11-05-2006 02:17 AM |
| making programms faster | deian | C Programming | 23 | 10-09-2004 12:19 AM |
| pointers | fanaonc | C Programming | 3 | 11-17-2001 02:18 AM |
| Please help newbie with Borland Compiler and simple code!! | tranced | C++ Programming | 3 | 11-04-2001 03:53 PM |
| Bad code or bad compiler? | musayume | C Programming | 3 | 10-22-2001 09:08 PM |