I use Visual Studio 2017 with ReSharper 2017.2 as the code editor for an embedded project. I managed to configure all but one thing:
How do I make VS/R# ignore that specific keyword, _Interrupt1? (this error causes other side effects).
I tried to add it as a preprocessor definition (Project's properties -> C/C++ -> Preprocessor -> Preprocessor Definitions), but it doesn't help.
I am not sure about R#, but in VS you could try to define globally:
#ifdef __INTELLISENSE__
#define _Interrupt1
#endif
to hide _Interrupt1 from Intellisense parsing.
For completeness, thanks to #Hans Passant, use __RESHARPER__ for RS
Related
I need to suppress a GCC (or what I believe is GCC) compiler warning in Visual Studio. Usually these Visual Studio compiler warnings come with a warning code, but this one is just null.
The warning is '__cdecl' attribute directive ignored [-Wattributes]. I believe I need to suppress all -Wattributes warnings for my .h file, but I am not sure how to do that.
The block that is giving me the troubles is inside LoggerHelper.h:
#ifdef _MSC_VER
using LoggerFuncPtr = void(__cdecl *)(wchar_t*);
#else
using LoggerFuncPtr = void(__attribute__((__cdecl)) *)(wchar_t*);
#endif
GCC's cdecl attribute doesn't have leading underscores, the declaration should look like:
#ifdef _MSC_VER
using LoggerFuncPtr = void(__cdecl *)(wchar_t*);
#else
using LoggerFuncPtr = void(__attribute__((cdecl)) *)(wchar_t*);
#endif
What is the best way to do this? The templates seem to allow only for C++ (which is basically compatible with C, but not the same.) What is the proper way to do this? (A particular #define or whatever.) Any help would be appreciated.
The solution is simple and easy
You create a new win32 console project
Remove the default .cpp file
Add new .c file as you wish
In Properties, under C/C++ --> All Options, find "Compile as", then select "Compile as C code"
Simple sanity check. This code doesn't work with C++ since "new" is a reserved word for C++.
int new = 10;
I have an existing C-Project with a pre-written Makefile. I imported the whole thing as a Makefile-Project into Eclipse and it is working fine so far - meaning I can navigate through the code with eclipse and I can build it without problems.
Now I added some Compiler Symbols like NO_ASMto my makefile and updated the code at some points with the according lines of
#ifdef NO_ASM
// Code
#endif
This code is greyed out by my Code-Editor. Now I added the Symbol NO_ASM to
Properties/C/C++ General/Paths and Symbols and rebuilt the indexer - but the according code is still grey. Is there any way to solve this?
Are you sure you added it to all configurations? in all Languages?
You can Try Freshen all files option.
A temporal workaround can something like this:
#ifndef NO_ASM
#define NO_ASM
#endif
I have a WPF application with three custom configurations. The are as follows:
Debug
Deploy_Local
Deploy_Beta
Deploy_Live
Obviously I can use a precompiler directive to detect Debug:
#if DEBUG
// Debug code
#else
// Non-debug code
#endif
How can I do this with the the remaining three configurations?
I believe this was answered somewhat in: Will #if RELEASE work like #if DEBUG does in C#?
Basically, you do need to also define custom symbols at the project level (in the build tab). So if you name your configuration MY_CONFIG, you will have to add the MY_CONFIG symbol to all the project that you want to handle that configuration specifically. You can then do the same construct as:
#if MY_CONFIG
Console.WriteLine("MY_CONFIG");
#endif
Hope this helps,
Eric.
what's wrong with:
#if DEBUG
#else
#if Deploy_Local
// and so on
#endif
#endif
I figured this out on my own. There is a "Conditional Compilation Symbols" in the "Build" tab of the project's settings. It's at least there in WPF applications. I added the precompiler symbols for each of my configurations therein.
I really hate giving the Answer to myself. Sigh! So can anyone elaborate on this?
I'm using eclipse to work on some c code and it is not indexing code inside conditional compilation blocks like this:
#ifdef USE_FEATURE_A
int feature_a(...) {
some = code(here);
}
#endif
How can I get eclipse to index the feature_a function?
You could tell eclipse that USE_FEATURE_A is defined. Open your project properties and go to the "C/C++ General->Paths and Symbols" page, under the "Symbols" tab click the "Add" button and put USE_FEATURE_A in the name feild and click OK.
Note: this will cause it not to index any #else sides to your preprocessor stuff... so unless they are all like the one in question you can't AFAIK, but if they are they you're good. (Eclipse contains a C preprocessor that it uses to analyize your code all the stuff above does is essentially the same as adding -DUSE_FEATURE_A to your command line so Eclipse's preprocessor will behave differently from the one in your compiler)
This is an easier and in my opinion more elegant solution to the one selected as the solution:
If someone has the same problem (as I had), this can (now?) easily be solved by going to Window->Preference->C/C++/Indexer and enable "Index all header variants".
Then click Project->C/C++ Indexer->rebuild and clean and build your project. This should resolve all error originating from preprocessor commands.
For what it's worth, getting eclipse to parse conditionally compiled code is much harder to do than would appear at first glance. I found a paper on by IBM from 2007 where they said they will prioritize for the "next release".
Handling Conditional Compilation in CDT's Core
I had this same problem, but the code conditionally eliminated by preprocessing was perfectly valid c code and I wanted it formatted... This was my solution:
1) Global find/replace of #if to #JUNKif
2) Ctrl-Shift-F to reformat the source
3) Another global find/replace of #JUNKif to #if
One way to index code under flag in Eclipse(Kepler) c/c++Editor.
You can enable the compilation flags in Eclipse editor so that code under them can be indexed.
Properties > Preprocessor Include Paths > CDT User settings Entries
Click on ADD and add the Preprocessor Macro and you can specify its value.
Best way I guess is to use the Indexer option : Project Properties>C/C++ General>Indexer.
You can choose Enable project specific settings
I prefer choosing "Use active build configuration" so that all files which are actually built in the project are indexed.
Anyhow you can also choose to index all files in the project even if they are not included in the build ...