preprocessor-directive

How to use #if to decide which platform is being compiled for in C#

南笙酒味 提交于 2019-12-04 11:26:10
问题 In C++ there are predefined macros: #if defined(_M_X64) || defined(__amd64__) // Building for 64bit target const unsigned long MaxGulpSize = 1048576 * 128;// megabyte = 1048576; const unsigned long MaxRecsCopy = 1048576 * 16; #else const unsigned long MaxGulpSize = 1048576 * 8;// megabyte = 1048576; const unsigned long MaxRecsCopy = 1048576; #endif Which allows me to set constants to control the amount of memory that will be used. Of course I can define a preprocessor variable verbatim:

Are there any preprocessor directives that control loop unrolling?

折月煮酒 提交于 2019-12-04 05:39:18
Furthermore, how does the compiler determine the extent to unroll a loop, assuming all operations in the loop are completely independent of other iterations. For MSVC there is only a vector independence hint: http://msdn.microsoft.com/en-us/library/hh923901.aspx #pragma loop( ivdep ) For many other compilers, like Intel / ibm , there a several pragma hints for optimizing a loop: #pragma unroll #pragma loop count N #pragma ivdep There is a thread with MSVC++ people about unroll heuristic: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/d0b225c2-f5b0-4bb9-ac6a-4d4f61f7cb17/ VC

Tool to remove/Apply ifdef's/else's from codebase

有些话、适合烂在心里 提交于 2019-12-04 03:32:36
问题 I have a pretty big codebase and I wanted to clean it out by removing and applying some ifdef's scattered around it. For example, I have lot's of these: test.c #ifdef MYCHECK // do other sutff #else // do stuff #endif Is there a tool that allows me to run through the entire codebase and remove all that code, leaving only the code inside my variable condition? For example: nicetool -D MYCHECK *.c Would result in: test.c // do other stuff 回答1: It looks like unifdef is what you want, it is also

What does #line mean?

落爺英雄遲暮 提交于 2019-12-04 01:34:06
What does the following line do? #line 25 "CSSGrammar.y" And what's with the extension? According to the Standard: §16.4.3: A preprocessing directive of the form # line digit-sequence new-line causes the implementation to behave as if the following sequence of source lines begins with a source line that has a line number as specified by the digit sequence (interpreted as a decimal integer). If the digit sequence specifies zero or a number greater than 2147483647, the behavior is undefined. §16.4.4: A preprocessing directive of the form # line digit-sequence " s-char-sequenceopt" new-line sets

Can I make a preprocessor directive dependent on the .NET framework version?

北慕城南 提交于 2019-12-04 01:10:09
Here's a concrete example of what I want to do. Consider the string.Join function. Pre-.NET 4.0, there were only two overloads, both of which required a string[] parameter. As of .NET 4.0, there are new overloads taking more flexible parameter types, including IEnumerable<string> . I have a library which includes a Join function that does essentially what the .NET 4.0 string.Join function does. I was just wondering if I could make this function's implementation dependent on the .NET framework being targeted. If 4.0, it could simply call string.Join internally. If 3.5 or older, it could call

Advantages of conditional-preprocessor over conditional statements

亡梦爱人 提交于 2019-12-04 00:50:08
问题 I have never worked with #if , #ifdef , #ifndef , #else , #elif and #endif . As I was going through some source-codes, I found an extensive use of these directives. Did some reading on conditional-preprocessors but found no clue like how are they different from normal conditional statements . So I was wondering what is the advantage of following code: #include<iostream> int main() { int i = 0; #if i == 0 std::cout<<"This"; #else std::cout<<"That"; #endif return 0; } over this: #include

How to poison an identifier in VC++?

馋奶兔 提交于 2019-12-03 12:45:40
Function poisoning is very useful technique in C++. In general it refers to making a function unusable, e.g. if you want to ban the use of dynamic allocation in a program you could "poison" the malloc function so it can't be used. 'Poisoning' an identifier means that any reference to the identifier after the 'poisoning' is a hard compiler error For example (See live demo here ) #include <iostream> #include <cstdlib> #pragma GCC poison malloc int main() { int* p=(int*)malloc(sizeof(int)); // compiler error use of poisoned function malloc *p=3; std::cout<<*p<<'\n'; free(p); } I found this

How to use #if to decide which platform is being compiled for in C#

混江龙づ霸主 提交于 2019-12-03 07:42:39
In C++ there are predefined macros: #if defined(_M_X64) || defined(__amd64__) // Building for 64bit target const unsigned long MaxGulpSize = 1048576 * 128;// megabyte = 1048576; const unsigned long MaxRecsCopy = 1048576 * 16; #else const unsigned long MaxGulpSize = 1048576 * 8;// megabyte = 1048576; const unsigned long MaxRecsCopy = 1048576; #endif Which allows me to set constants to control the amount of memory that will be used. Of course I can define a preprocessor variable verbatim: #define Is64bit 1 using System; using System.Collections.Generic; -later- #if Is64bit // Building for 64bit

CMake: Set different name for #cmakedefine variable

﹥>﹥吖頭↗ 提交于 2019-12-02 14:52:53
问题 I know you can use CMake's configure_file to make CMake variables available to your program. For example, I can use #define ${CMAKE_BUILD_TYPE} resulting in #define Release However, to keep my code more readible, I would prefer to define #define BUILD_TYPE_RELEASE Is there a simple way to achieve this? 回答1: Here is a fairly simple way to solve it: In CMakesLists.txt : if (NOT CMAKE_BUILD_TYPE) set (CMAKE_BUILD_TYPE Release) endif (NOT CMAKE_BUILD_TYPE) string (TOUPPER ${CMAKE_BUILD_TYPE}

Are there C like pre-processor directives for Octave and Scilab to be used for intercompatible code?

谁都会走 提交于 2019-12-02 04:47:54
In C / C++ languages one can use macros or as called "per-processor directives" to instruct the compiler how the code should be read. The simple commands of #def , #ifdef , #ifndef , #else , #endif ... give the compiler the ability to check for Operating system, compiler and other environment information. I know Octave and Scilab are interpreted languages, but I'm wondering if is there any way to tell the interpreter to replaces parts of script while loading it? For example can I write a code which is commented based on Scilab syntax // and then instruct the interpreter to read them as Octave