Is it possible to use #define
in an "if" statement? The following code works, but I get a warning that the macro is being redefined.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
#define TableViewHeight 916
#define DisplayHeight 1024
#define DisplayWidth 768
}
else {
#define TableViewHeight 374
#define DisplayHeight 480
#define DisplayWidth 320
}
I also tried this, but it didn't work:
#ifdef UIUserInterfaceIdiomPad
#define TableViewHeight 916
#define DisplayHeight 1024
#define DisplayWidth 768
#else
#define TableViewHeight 374
#define DisplayHeight 480
#define DisplayWidth 320
#endif
Any ideas?
The words employ and utilize are common synonyms of use. While all three words mean "to put into service especially to attain an end," use implies availing oneself of something as a means or instrument to an end.
Verb. use, employ, utilize mean to put into service especially to attain an end. use implies availing oneself of something as a means or instrument to an end. willing to use any means to achieve her ends employ suggests the use of a person or thing that is available but idle, inactive, or disengaged.
transitive verb. If you say that someone uses people, you disapprove of them because they make others do things for them in order to benefit or gain some advantage from it, and not because they care about the other people. [disapproval]
The words employ and use are common synonyms of utilize.
Yes, it's possible but it probably doesn't do what you think. Preprocessor directives are interpreted before the results of the preprocessing step are compiled.
This means that all of the preprocessor directives are interpreted, redefining some of the macros, before the remaining code, which will look something like below, is compiled.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
}
else {
}
In other words, after preprocessing, you just have empty if
and else
bodies.
If you want to change the value of something based on a condition at run time then that something will have to be an genuine object and not just a preprocessor macro. E.g.
extern int TableViewHeight; // defined somewhere else
extern int DisplayHeight; // defined somewhere else
extern int DisplayWidth; // defined somewhere else
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
TableViewHeight = 916;
DisplayHeight = 1024;
DisplayWidth = 768;
}
else {
TableViewHeight = 374;
DisplayHeight = 480;
DisplayWidth = 320;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With