I currently have a visual studio project that uses DirectX. There are some macros in the code such as
__range(0, m_lBatchSize) LONG m_nBatched;
__field_ecount_opt(m_lBatchSize) IMediaSample ** m_ppSamples;
I wanted to know which files these macros are defined in. Normally in Visual Studio I would click goto definition and it would take me to the definitio. It is not taking me anywhere in this case. Does that feature work for macros ? Is there any way for me to find out where this macro is defined ?
my trick is to put
#define __range FOO
in my code, the preprocessor will then say
__range already defined at xxxx.nn
Related
It is a possible to pass argument to compiler (command line) and set defined variables:
Example:
#define EXVALUE
and I want to define EXVALUE at compiling:
application.cpp -8
'-8' it is a command line argument to define EXVALUE. So I hope that You will understand
what I want, and will help me.
I use Visual Studio C++ 2008 Express Edition.
Thanks. (Sorry for english bads)
Visual Studio (so also Visual C++ EE) uses /D option.
Example:
/D "BOOST_ALL_STATIC_LINK"
You can do it by GUI : Project Properties->C/C++->Preprocessor->Preprocessor Definitions
First link in Google for visual studio preprocessor definitions has really nice information, if you need more.
From my earlier post, I figured out why the command
build /nmake "USER_C_FLAGS=/DMyVersion=3"
doesn't associate the define MyVersion with value 3. MSDN says that -
Compiling with /Dname= causes the symbol to not have an associated
value. So, while the symbol can still be used to conditionally compile
code, the symbol will otherwise evaluate to nothing. For example, in
the previous sample program, compiling with /DTEST= will cause a
compiler error. This behavior is similar to using #define with or
without a value.
I have an environment variable that gets set up at run-time and I need to pass that env. variable to the Visual Studio 2005 Makefile Project. Now the question is, how can I pass the env. variable to the run-time build environment ? Once passed, I should be able to something like -
#define VERSION 11
#ifdef BUILD_VERSION // How to get this macro to the current env. ?
#undef VERSION
#define VERSION BUILD_VERSION
#endif
#define FILE_VERSION VERSION
I don't see any flags from nmake documentation to pass env. variables. Any ideas are highly appreciated.
MSDN will answer this for nmake Environment-Variable Macros.
Pay attention here: "Use the /E option to cause macros inherited from environment variables to override any macros with the same name in the makefile."
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
I'm trying to compile some source code with Visual C++ 2010 Express. The code was written for GCC, and contains attributes like this:
struct something {
...
} __attribute__((packed));
Since this is not standard C++ syntax, Visual C++ doesn't recognize it. With this macro prior to the struct declaration, it works fine:
#define __attribute__(p)
But I don't want to alter the files. I created a new property sheet (GccCompat), and went to Preprocessor Definitions, and added the macro, like this:
__attribute__(p)
or like this:
__attribute__(p)=
But it doesn't work. It's simply not called. If I define just __attribute__ (without parameters) in the same location, the macro is correctly defined. Note that the command line that is generated looks fine (the macros with parameters are passed exactly the same as the ones without), but the compiler seems to ignore it. So, how can I globally define my macro with a parameter?
It might be impossible, at least that way. Notice that Microsoft's documentation of the /D option doesn't specify a syntax for macros that take arguments.
Defining macros in the IDE is generally focused on the nature of creating a /D:CPP_TOKEN flag for the compiler, i.e. #define CPP_TOKEN.
In the advanced compiler settings you may be able to define such a macro as /D:"attributes(p)=/nothing/" or something like that. Just open the VS command prompt and see what it says. GCC 4.2 will allow something like that (using it's -D switch), but I don't have MSVC10 handy.