preprocessor-directive

Determine if the device is ARM64

落爺英雄遲暮 提交于 2019-12-02 02:04:40
问题 I'm trying to make a tweak for iOS 7 so that when a device is ARM64 it runs one version and when it is not it runs another (since float is for 32 bit and double is for 64 (If you have a solution for that let me know.) So it would be like this if ARM64 { \\run double code } else { \\run float code } 回答1: You would do the following #if __LP64__ \\You're running on 64 bit #else \\You're running on 32 bit #endif 回答2: On arm64 environment, the pointer take 8 bytes. - (BOOL)isArm64 { static BOOL

Tool to remove/Apply ifdef's/else's from codebase

六眼飞鱼酱① 提交于 2019-12-01 18:17:32
I have a pretty big codebase and I wanted to clean it out by removing and applying some ifdef's scattered around it. For example, I have lot's of these: test.c #ifdef MYCHECK // do other sutff #else // do stuff #endif Is there a tool that allows me to run through the entire codebase and remove all that code, leaving only the code inside my variable condition? For example: nicetool -D MYCHECK *.c Would result in: test.c // do other stuff It looks like unifdef is what you want, it is also used in the Linux kernel . This is the description of the tool from the linked site ( emphasis mine ): The

Advantages of conditional-preprocessor over conditional statements

梦想与她 提交于 2019-12-01 03:53:05
I have never worked with #if , #ifdef , #ifndef , #else , #elif and #endif . As I was going through some source-codes, I found an extensive use of these directives. Did some reading on conditional-preprocessors but found no clue like how are they different from normal conditional statements . So I was wondering what is the advantage of following code: #include<iostream> int main() { int i = 0; #if i == 0 std::cout<<"This"; #else std::cout<<"That"; #endif return 0; } over this: #include<iostream> int main() { int i = 0; if (i == 0) std::cout<<"This"; else std::cout<<"That"; return 0; } Also,

Visual Studio ignores the code inside #if DEBUG / RELEASE scope and doesn't check for errors or autocompletes

拥有回忆 提交于 2019-12-01 02:44:42
问题 I've been writing an #if DEBUG , #else , #endif fragment of code, and I noticed that Visual Studio doesn't let me use autocomplete to fulfill partially typed member names, and it doesn't check the greyed out inactive code for errors. The only way I've found to make it care again is to switch the build mode from Debug to Release. But that's inconvenient and feels like there's a better way. example: #if DEBUG throw; #else throw new exc // I want to use autocomplete here but can't because it's

C macro to enable and disable code features

て烟熏妆下的殇ゞ 提交于 2019-12-01 01:30:33
I've used a code base before that had a macro system for enabling and disabling sections of code. It looked something like the following: #define IN_USE X #define NOT_IN_USE _ #if defined( WIN32 ) #define FEATURE_A IN_USE #define FEATURE_B IN_USE #define FEATURE_C NOT_IN_USE #elif defined( OSX ) #define FEATURE_A NOT_IN_USE #define FEATURE_B NOT_IN_USE #define FEATURE_C IN_USE #else #define FEATURE_A NOT_IN_USE #define FEATURE_B NOT_IN_USE #define FEATURE_C NOT_IN_USE #endif Then the code for the features would look like: void DoFeatures() { #if USING( FEATURE_A ) // Feature A code... #endif

C macro to enable and disable code features

故事扮演 提交于 2019-11-30 20:08:23
问题 I've used a code base before that had a macro system for enabling and disabling sections of code. It looked something like the following: #define IN_USE X #define NOT_IN_USE _ #if defined( WIN32 ) #define FEATURE_A IN_USE #define FEATURE_B IN_USE #define FEATURE_C NOT_IN_USE #elif defined( OSX ) #define FEATURE_A NOT_IN_USE #define FEATURE_B NOT_IN_USE #define FEATURE_C IN_USE #else #define FEATURE_A NOT_IN_USE #define FEATURE_B NOT_IN_USE #define FEATURE_C NOT_IN_USE #endif Then the code for

#if vs #ifndef vs #ifdef

北城余情 提交于 2019-11-30 15:34:54
My problem is first of all, understanding #ifndef and #ifdef . I also want to understand the difference between #if , #ifndef , and #ifdef . I understand that #if is basically an if statement. For example: #include<iostream> #define LINUX_GRAPHICS 011x101 int main(){ long Compare = LINUX_GRAPHICS; #if Compare == LINUX_GRAPHICS std::cout << "True" << std::endl; #endif } But the others, although I read about them I can't comprehend. They also seem like very similar terms, but I doubt they work similarly. Help would be greatly appreciated. Macros are expanded by the preprocessor who doesnt know

#if preprocessor directive for directives other than DEBUG

不想你离开。 提交于 2019-11-30 11:05:25
I know that I can use preprocessor directives to check for Debug/Release by doing this: #if DEBUG //debug mode #elif //release mode #endif but what about checking for other configurations, like Test. In VB you can do this: #If CONFIG = "Release" Then 'Release mode #ElseIf CONFIG = "Test" Then 'Test mode #ElseIf CONFIG = "Debug" Then 'Debug mode #End If So, my question is in C#, how can I check for Test mode? I have some code that I want to execute if I'm in Debug AND Test, but not in Release mode, so specifically, I need a way to check for not being in Release mode. In VB I would do this: #If

#if vs #ifndef vs #ifdef

旧城冷巷雨未停 提交于 2019-11-29 21:15:15
问题 My problem is first of all, understanding #ifndef and #ifdef . I also want to understand the difference between #if , #ifndef , and #ifdef . I understand that #if is basically an if statement. For example: #include<iostream> #define LINUX_GRAPHICS 011x101 int main(){ long Compare = LINUX_GRAPHICS; #if Compare == LINUX_GRAPHICS std::cout << "True" << std::endl; #endif } But the others, although I read about them I can't comprehend. They also seem like very similar terms, but I doubt they work

Is #define banned in industry standards?

谁说我不能喝 提交于 2019-11-29 21:11:43
I am a first year computer science student and my professor said #define is banned in the industry standards along with #if , #ifdef , #else , and a few other preprocessor directives. He used the word "banned" because of unexpected behaviour. Is this accurate? If so why? Are there, in fact, any standards which prohibit the use of these directives? Jonathan Leffler First I've heard of it. No; #define and so on are widely used. Sometimes too widely used, but definitely used. There are places where the C standard mandates the use of macros — you can't avoid those easily. For example, §7.5 Errors