Turn on autocomplete/hints for code between preprocessor lines - ide

I have some code wrapped between the following statements:
#if POTATO
(a few lines of c code)
#endif
Unfortunately, autocompletion, highlighting, suggestions and everything else stops working for any code between the #if statements. How can I fix this?

Related

ObjC macro ifdef and defined

I'm trying to do a macro where if AAA and BBB does not exists. Something like this:
#ifdef !AAA && !BBB
#endif
or this:
#ifndef AAA || BBB
#endif
However, Xcode is throwing me errors, so I've tried
#ifdef !(defined AAA) && !(defined BBB)
or some other such combinations and it seems like Xcode doesn't seems to understand defined. I'm getting "Macro names must be identifiers" or "Extra tokens at the end of #ifdef directive" errors.
Any idea how I could workaround this problem?
Can you just use #if?
#if !defined(AAA) && !defined(BBB)

Is there a way to use a block comment on a section that's already commented?

I know you can comment out a whole section of code like so:
/*
line of code
line of code
line of code
*/
But if you already have a /* ... */ section in the code that you are trying to comment, then the */ end of a comment block will close the "greater" comment block I am trying to create.
Example:
/* wanting to comment this big section out
line of code
line of code
line of code
line of code
line of code
line of code
/* this section was already commented out before
line of code
line of code
line of code
*/ this section was already commented out before
line of code
line of code
line of code
line of code
line of code
*/ this last part doesn't get commented out, because the comment stops at previous */
Obviously this isn't a huge big deal, it is not stopping me from getting an app to work properly, but I'm just wondering if there might be some way of commenting out a larger section of code, even if there are already comment blocks in that code.
Highlight the code you want commented out and press "Command" + "/"
To avoid such a situation, always use // for commenting and use Xcode shortcut to comment a block of code.
The shortcut is cmd + /
I'd frown if I saw it in code, but you can do
#if 0
...code...
#endif

Xcode #ifdef DEBUG is not working properly

I have add following line to the code.
#ifdef DEBUG
//DEBUG only code
#endif
And I have go to the project->info tab in the xcode and set 'command-line builds use' to debug and run the code the code snippet inside the 'if' executed. The problem is when i set the command-line build' use to release and run the code. The code snippet inside the if condition still runs. I have set the preprocessor DEBUG macros to 'DEBUG=1'without quotes. How to solve this.
The #ifdef syntax means "is defined", without regard to value; in other words, it is defined if it has any value at all (0 or 1).
You probably want the #if syntax instead. This requires that the value actually be set to 1.

Unterminated conditional directive in Xcode

What's wrong here:
#define CONTROLS_OFFSET 100
#ifdef CONTROLS_OFFSET//Unterminated conditional directive it says
#define FIND_MAIN_MENU 3
Why do i get this error?
An #ifdef, like an #if, needs to be balanced by an #endif. In this case, that would probably go immediately after your #define line.
Something like this:
#ifdef DEBUG
NSLog (#"This is a test");
#endif

MinGW and "declaration does not declare anything"

I'm working on converting a Linux project of mine to compile on Windows using MinGW. It compiles and runs just fine on Linux, but when I attempt to compile it with MinGW it bombs out with the following error message:
camera.h:11: error: declaration does not declare anything
camera.h:12: error: declaration does not declare anything
I'm kind of baffled why this is happening, because
I'm using the same version of g++ (4.4) on both Linux and Windows (via MinGW).
The contents of camera.h is absurdly simple.
Here's the code. It's choking on lines 11 and 12 where float near; and float far; are defined.
#include "Vector.h"
#ifndef _CAMERA_H_
#define _CAMERA_H_
class Camera{
public:
Vector eye;
Vector lookAt;
float fov;
float near;
float far;
};
#endif
Thanks for your help.
EDIT: Thanks both Dirk and mingos, that was exactly the problem!
Edit If you happen to include windef.h (either directly or indirectly), you will find
#define FAR
#define far
#define NEAR
#define near
there. I think, that this is the culprit.
Try
#undef near
#undef far
before your class definition.
Try giving them different names, like
float my_near;
float my_far;
I recall Borland using "near" and "far" as keywords (my 1992 Turbo C had these, back in MS-DOS era). Dunno if this is the case with gcc, but you can always try that.
In <windef.h>, you'll find on the following lines:
#define NEAR
#define near
Simple answer: you can't #undef them because they're a part of the Windows headers (_WINDEF_H will still be defined even if you #undef those definitions, so it won't be re-included if you try to #include <windef.h> again, not to mention the fact that if you #undef _WINDEF_H before using #include <windef.h> after your class definition, you'll end up with duplicate definitions for things like RECT, LONG, PROC and more), so the only other solution is to change your variable names.