I have an issue with C++ macros. So I have this two Macros to help with OpenGL error handling. I have to basically wrap this Macro with any OpenGL function I attempt to call. The problem is that this GLCall macro prevents intellisense for anything I attempt to write below it. Anyone know what the issue might be? intellisense works perfectly above any GLCall() line by the way.
the code
#define ASSERT(x) if(!(x))__debugbreak();
#define GLCall(x) GLClearError(); x; ASSERT(GLLogCall(#x, __FILE__, __LINE__));
Visual Studios default intellisense is not the most intelligent. All I did was install Visual Assist and everything worked well.
Related
When I try to run the following header
https://github.com/marmalade/glib/blob/master/glibconfig.h
in Microsoft Visual Studio, I get the following error: 'G_CAN_INLINE': macro redefinition. What is the reason for this? Any help is appreciated. Thanks.
There's actually a trick for this which might work for you. What you can do is this:
Comment out the #define(s) for G_CAN_INLINE in glibconfig.h (make a copy first!).
After the relevant #include, add (temporarily) the following line to the source file that is generating the compiler error:
int any_old_variable_name = G_CAN_INLINE;
Give Intellisense a moment to catch up.
Right-click on G_CAN_INLINE and select 'Go To Definition'.
With a bit of luck, VS will then show you where that macro is (also) being defined and that should help you figure out what to do.
Having said which, G_CAN_INLINE doesn't look to be all that important. You will probably find that you can just #undef it before you include glibconfig.
I hope this is an interesting question. I'm trying to find the source of an unresolved external symbol. I have debug code that uses a global file pointer if debugging is turned on. All of this debugging code is supposed to be protected by #ifdef, like:
#ifdef DO_XLL_DEBUG
fprintf(debugPointer, "hello\n);
...
#endif
When I define DO_XLL_DEBUG, all is well. If I undef DO_XLL_DEBUG, everything compiles (I do a rebuild all just in case), but it fails at the link step, not finding debugPointer.
So, the question is, is there an easy way to find where I failed to #ifdef around the debug code? I can think of several not so easy ways.
I'm using Visual Studio 2005. This is a C++ project.
Thanks!
[EDIT]
Thanks for all the suggestions. Turns out the problem was in someone else's code that is not part the corresponding project I'm working on in Linux (where I do most of my work), so no wonder I didn't find it right away.
Just define some incompatible debugPointer and let the compiler point you at all the places where it's accidentially used or redefined. Maybe like this:
#ifndef DO_XLL_DEBUG
#define debugPointer static_assert(false,"damn it!");
#endif
(given that you don't have other variables, parameters, etc. which are called debugPointer)
I'm an intern student and my boss told me to do porting from Linux c to Visual C++.
When I built the coding, I found this error "unexpected in macro formal parameter list", here is the code
#define cache_info(format, msg...)
do { \
;\
} while (0)
I don't know what is wrong and what the coding is for .
I can't also ask the Linux programmer since he is out. Can someone help me ???
Sounds like your version of Visual C++ doesn't support variadic macros.
you might need to try something like this to get it to work.
#define FUNC(foo) ThisFunc foo
void ThisFunc(int, ...);
int main()
{
FUNC((123, 456));
}
or you could just be missing a comma?....
#define cache_info(format, msg,...)
I think that the problem could be from one of two things.
First, your macro is defined as
cache_info(format, msg...)
But you probably meant to write
cache_info(format, msg, ...)
Though this could just be a typo in your original post.
More importantly, though, macros with variable numbers of arguments ("variadic macros") are not supported in C++; they exist only in C. If you're trying to compile this C code with a C++ compiler, the compiler should give you an error here because the code isn't legal C++.
if using Windows 64 bit OS, & visual studio, try after running this bat file : \Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat
It will register env settings. It worked for me..
I switched from Visual Studio to Code::Blocks yesterday, and just had some strange compiler error messages.
I included windows.h and i can use all the API calls just fine, such as creating window classes and creating windows / buttons and stuff. But when I tried to send some keypresses with SendInput(), I got error messages on these two declarations:
INPUT ip;
KEYBDINPUT kbi;
Compiler errors:
C:\code_blocks\test-app\main.cpp|21|error: 'INPUT' was not declared in this scope|
C:\code_blocks\test-app\main.cpp|22|error: 'KEYBDINPUT' was not declared in this scope|
I can even right click the KEYBDINPUT and INPUT structors and click on "Find declaration", it finds it inside the "winuser.h" (which is inside ), but it's still giving me these error messages that they are not declared.
This code works fine in VS with just windows.h included. I'm using the GNU GCC compiler.
I think you need the pre-processor directives (Visual Studio may already add them):
What do you have _WIN32_WINNT defined as?
Perhaps you could add:
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
or you can add it to your pre-processor directives as part of your compile sequence. Any good compiler will have it.
If it still doesn't work, remove the include guards and define it directly. Maybe it is getting defined elsewhere.
Some compilers will have this in the pre-processor directive settings: WIN32,_DEBUG,_CONSOLE,_MBCS,_WIN32_WINNT=0x0400
To elaborate on Changeling's answer, if you look at the documentation for say KEYBDINPUT, you will see that near the bottom it has a table of minimal supported OS versions. VC++ sets _WIN32_WINNT to a later version than MinGW/GCC (which I am guessing is the compiler you are using with Code::Blocks), which is probably why you have encountered this problem.
The purpose of this macro is to prevent you inadvertently using API's that are not compatible with your minimum intended target OS.
There are a number of version related macros used by Windows API headers. The details can be found here
eMbedded Visual C++ 3 project, that is building for PocketPC 2000. On the ARM build, the linker throws the following error:
fatal error LNK1223: invalid or corrupt file: file contains invalid pdata contributions
On SH3, the project compiles, links, and works. The project also works when built for ARM on Visual C++ 2005, but I need to test builds specifically from eVC3.
Any ideas, please? What's a pdata contribution and how do I affect (or disable) those? It's something to do with exception handling; I've tried disabling SEH by specifying /EHsc, to no effect.
Very weird. I tried commenting out everything in the file. The error went away when I commented out a function that was extern "C" void __declspec(naked) with no body (body #ifdef'fed away). I have similar functions in the project, but they did not throw any errors like this. Maybe a compiler bug...
No idea from me, but the Google-mind dredged up this thread which might give you a clue how to fix/workaround the problem... maybe:
http://www.pocketpcjunkies.com/Uwe/Forum.aspx/wince-pb/7477/Link-error-during-DEBUG-build
After looking at the error more closely, I finally figured out that this is
a side-effect of my hijacking of SC_SetDaylightTime() in the kernel with my
own version. Apparently, something that I'm doing in my code there is
causing the compiler to generate pdata entries that are wrong in some way.
A strategically-placed #ifndef worked around it.