Is it still an issue in VS2013 update 4
I have this macro defined:
#define STR LR"(c:\program files)"
However when compiling below
cout<< STR
I get a compilation warning (warning C4129: 'p'), seems like the compiler disregards macro expansion of the Raw literal directive.
Is it still a compiler bug? When Microsoft shall fix it?
Related
I was attempting to get Eigen working with some code in Visual Studios 2019 using Visual Studios 2015 build tools.
I would like to confirm that Eigen is detecting and enabling its vectorization.
According to Eigen FAQ, Eigen "will automatically enable its vectorization if a supported SIMD instruction set and a supported compiler are detected".
I have the "Maximize Speed" flag (/O2) turned on in Project->Properties->Configuration Properties->C/C++->Optimization
Also according to Eigen FAQ, in order to check that vectorization is being used, "First you can check that Eigen vectorization is enabled: the EIGEN_VECTORIZE preprocessor symbol is then defined."
If I look under Project->Properties->Configuration Properties->C/C++->Preprocessor, I do not see EIGEN_VECTORIZE listed.
Does this mean that it is not defined? How do I check for this preprocessor symbol?
You don't define EIGEN_VECTORIZE, it gets defined in the Eigen/Core file. Basically, the code reads as:
#ifndef EIGEN_DONT_VECTORIZE
#define EIGEN_VECTORIZE
#define EIGEN_VECTORIZE_SSE
#define EIGEN_VECTORIZE_SSE2
and continues on to check if each instruction set is being used, and if so defining EIGEN_VECTORIZE_YYY (where YYY is the instruction set). One thing to note, is that MSVC does not have definitions for SSE greater than 2. If you want to use those instructions, you'll have to explicitly define EIGEN_VECTORIZE_SSE3, EIGEN_VECTORIZE_SSSE3, EIGEN_VECTORIZE_SSE4_1, EIGEN_VECTORIZE_SSE4_2. I'm not sure if it defines __FMA__ either, so you would probably want tot define EIGEN_VECTORIZE_FMA if you enable AVX2.
VS2005 is very long in the tooth, but it is the tool I have to use.
My preference is to require that all preprocessor symbols be defined, but I can't find a way to cause VS2005 to generate an error if an undefined preprocessor symbol is referenced.
e.g.
in moo.h
#define _DEFN_WITH_TYPOE (1)
in cow.cpp
#include "moo.h"
#if _DEFN_WITH_TYPO
[various code bits]
#endif // _DEFN_WITH_TYPO
should generate an error, rather than treating _DEFN_WITH_TYPO as defined with value 0.
Is there an option that will do this?
TIA.
Assume that you have a label in a legacy Visual C++ 2010 project, defined like so:
[foo.rc]
LTEXT "Foo",IDC_STATIC,42,42,42,42
In a resource (.rc) file.
Now, you want to generate the text based on constants you define in a header file, like so:
[foo.rc]
LTEXT FOO_TEXT,IDC_STATIC,42,42,42,42
Where FOO_TEXT was previously defined in some other way, for instance:
[bar.h]
#define FROBNICATE "F"
#define OO "o"
#define ICANTTHINKOFMETASYNTACTICVARIABLESBEGINNINGWITHO "o"
#define FOO_TEXT (FROBNICATE OO ICANTTHINKOFMETASYNTACTICVARIABLESBEGINNINGWITHO)
Only that that doesn't work, because .rc files are not header files, and the RC compiler complains, telling you:
[Build output]
1>foo.rc(42): error RC2116: expecting number for ID
1>
1>
1>foo.rc(42): error RC2108: expected numerical dialog constant
What would you do?
To clarify, yes, the entire string in question is known at compile-time, but it also needs to be constructed from smaller strings (in this case, version information and release category (development, release, and another one)). Of course, I could also write C++ code that does that, but that seems very inelegant to me.
So, is there a nicer way?
I don't think you will be able to achive what you want without C++ code. See the comment to this msdn article:
Don't use parens in #define
The resource compiler is very limited in its understanding of directives. So, for example, this:
#define RESTYPE_FILE (256)
will silently get ignored, while this:
#define RESTYPE_FILE 256
will work. Obviously, trying to use expressions or anything complicated like that will silently fail, leaving you wondering why you can't load that resource.
I have some Microsoft code (XLCALL.CPP) which I am trying to compile with CodeBlocks/MinGW.
At this line I get a compile time error:
__forceinline void FetchExcel12EntryPt(void)
This is the error message I get:
XLCALL.CPP|36|error: expected constructor, destructor, or type
conversion before 'void'
This error is expected, because __forceinline is a Microsoft specific addition to the language, not recognized by GCC.
So, to get things compile, I try to add thiese defines in CodeBlocks (Project Build Options/Compiler Settings/#defines):
#define __forceinline inline
#define __forceinline
However I still get the same error.
If in the dialog I do not specify the #define preprocessor command (i.e.: __forceinline inline), this is what I get:
XLCALL.CPP|36|error: expected unqualified-id before numeric constant
Is there a way to compile such a piece of code, without using Visual C++?
The syntax is __forceinline=inline, as you've noted in the comments, because these settings get turned into -D options to GCC.
Note that inline is a strong hint to GCC that the function should be inlined, but does not guarantee it. The GCC equivalent of __forceinline is the always_inline attribute - e.g. this code:
#define __forceinline __attribute__((always_inline))
or equivalently this setting:
__forceinline="__attribute__((always_inline))"
(But this might well be unnecessary: if there was some particularly good reason for forcing this function to be inlined when compiling with MSVC, that reason may well not be valid when using a completely different compiler!)
Googling for an windows example of a recursive search i found this but trying to compile this with cl (and the MSVC++ tool chain) the compiler states error over error. Do I need to include some extra libraries directly as soon as i am not using the usual setup done by the MSVC++ GUI.
The posted example error codes are translated and therefore might not look exactly like they would in English.
"*": This referencing cannot be done for System::String the compiler substitutes "*" by
"^" to continue analysis
and
System::String ^ a system-owned array cannot contain this managed type
both those errors are on this line
String* directories[] = Directory::GetDirectories(dir.c_str()); //dir is a usual string
and therefore are not my coding.
What am I messing up?
The compile-line was:
cl /w /c /clr file.cpp
Directory::GetDeirectories is a .net call so it will return a .net object. You are trying to cast it to a c++ pointer. Your best bet is to declare a .net string array instead. The type is like so
array<String^>^ directories = Directory::GetDirectories(dir.c_str());