FAQ Database Discussion Community


Are there some source code shorteners? [closed]

c++,preprocessor
I am looking for a program that would read C++ source code, remove all unnecessary whitespace and replace all names so that the source code as measured by the number of bytes is as short as possible. I do not care about the obfuscation, size is all that matters. I...

Order of linked libraries in XCode

xcode,preprocessor,compile-time,compiler-directives
In an XCode project I have linkend a library (libpng) and a framework (opencv). The framework already contains an older version of my library. Now when I go to XCode in "Link Binary With Libraies", if I put opencv first and libpng second, my code will use the what is...

Getting a macro to concat AND stringify

c++,c,preprocessor
The approach to concatenate in C/C++ in a preprocessor macro is to use ##. The approach to stringify is to use #. I'm trying to concat AND stringify. This is generating a warning from g++ (3.3.2) #define TOKENPASTE(x, y) x ## y #define TOKENPASTE2(x, y) TOKENPASTE(x, y) // concat #define...

Using preprocessor conditionals in macro functions with double parentheses

c,syntax,preprocessor,preprocessor-directive
Given: #define TRACE(x) do { if (DEBUG) dbg_print x; } while (0) I want: TRACE(( "Message: %s" #ifdef MYDEF "Additional stuff" #endif , msg)); But gives error: error C2121: '#' invalid character : possibly the result of a macro expansion error C2146: syntax error : missing ')' before identifier 'ifdef'...

#ifdef with warning if misspelled

c++,preprocessor
I would like to use preprocessor directives to check if I have to include some part of my program warning me if I did a mistake or forgot to include the header containing the options. See the following example, is there a more common way to do that with only...

Can #define include previously defined variables?

c,preprocessor
How are the definitions in C processed? Are they processed in order of line numbers? For example, will the following statements work? #define ONE 1 #define TWO (ONE+1) Could there be any problems with definitions that depend on previous definitions? Thanks. ...

Fix broken txt files from GREP reports

excel,text,grep,notepad++,preprocessor
I get a report from the companies servers (of which I have no control) in the form of grep txt dumps. I need to process them to get the info in a sane manner, which I use excel, and it works great. Problem is, sometimes there are a few txt...

Compiled SASS into CSS is not showing my images or fonts

css,image,fonts,sass,preprocessor
So I compiled my SASS into one css file using codekit 2 on their own localhost and the website looks perfectly fine. However when I upload my website onto a webserver (including all my SASS and CSS) it will not show some of my images. Then when I remove the...

Xcode breakpoint when using fstream

c++,xcode,preprocessor
I usually use VS, but I decided to give Xcode a try. I'm having trouble opening files in Xcode. The file does exist, and I set the working directory to the directory where the .cpp, .h and .txt file is located. Do I have to tinker with the preprocessor? What...

C preprocessor macros: compacting code based on a single variance

c++,c,macros,preprocessor
My issue is this: I have some macros that look like this: #define _EI_PORTLETTER 'D' ...code... #if _EI_PORTLETTER == 'C' #define _EI_VECTOR PORTC_VECT if _EI_PORTLETTER == 'D' #define _EI_VECTOR PORTD_VECT #endif Then later in my code I have: ISR(_EI_VECTOR, ISR_NAKED) { ...code... } What I would like to be able...

Check for a definition of a macro inside a macro

c,macros,preprocessor
suppose I have this code: #define NAME MY_APP #define ENABLE NAME ## _ENABLE I want to check if the macro that ENABLE expands to is defined, i.e., if MY_APP_ENABLE is defined. Is this possible using C macros? Thank you....

Define body is another define

c,preprocessor
I cannot explicitly find an answer to this, seems to work in practice: // example #1 #define test 5 #define test2 test (test2 == 5) == true And even this: // example #2 #define test2 test #define test 5 Is there an explicit C spec rule that allows this. I...

Dose VS2010 pre-calculate preprocessor defined by #define?

c++,visual-studio-2010,macros,preprocessor
For Visual Studio 2010, if I define #define PI 4.0f*atan(1.0f) when PI is used somewhere later in the code, does the value needs to be calculate again or simply 3.1415926... being plugged in? Thanks. EDIT: Because I heard someone says the compiler might optimize to replace it with 3.1415926.., depending...

Pre process file before file_get_contents

php,preprocessor,file-get-contents
I was wondering, in PHP, if there was a way to get PHP to pre-process a file before writing it to a string. Example: I have index.php, which instantiates a class which calls file_get_contents depending on what GET parameter has been passed in via the .htaccess. I have some variables...

Can you add preprocessor directives in assembly?

c,assembly,preprocessor
I would like to execute some assembly instructions based on a define from a header file. Let's say in test.h I have #define DEBUG. In test.asm I want to check somehow like #ifdef DEBUG do something... Is such thing possible? I was not able to find something helpful in the...

Rotate color hue when iterating through a loop using stylus

css,loops,iteration,preprocessor,stylus
How can I spin the color hue for each item in a loop. If I have: items = { item1: 'item1', item2: 'item2', item3: 'item3' } For each item in this list I want to change it's hue by 30% Something like this: for name, item in items .{name} color:...

NS_ENUM & NS_OPTIONS: targeting a previous version of iOS 6 or OS X ML

objective-c,ios6,macros,compilation,preprocessor
I'm reading about NS_ENUM & NS_OPTIONS. The author says: If you'd like to use either macro when targeting a previous version of iOS or OS X, you can simply inline like so: #ifndef NS_ENUM #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type #endif Is there any...

conditional compilation confusion and failure

c++,c,makefile,preprocessor
I want to compile different files with a common *.c file. Like I want to compile A.c common.c xor B.c common.c but I can't figure out how to achieve that. Can you please tell me how do I make common.c use different headers without using my text editor to change...

Less: passing variable variable into lighten function

css,less,preprocessor
This works: background-color: ~"@{@{space-name}-color-4}"; This does not: background-color:lighten(~"@{@{space-name}-color-4}",5%); Error: SyntaxError: error evaluating function `lighten`: Object # has no method 'toHSL' in ... Checked questions on SO already and this one seems to be similar: Define variable name with variable in LESS operation Unfortunately this did not work for me, when...

proprocessors in C++ and their alternatives in Scala

scala,macros,preprocessor
Which is the alternative implementation in Scala of preprocessor directives, like in C++? Let say that I have something like this: #ifdef ADD class Add extends Expr { Expr left , right ; Add ( Expr l, Expr r) { left =l; right =r; } #ifdef EVAL double eval ()...

Avoid redefinition preprocessor variable

c++,variables,preprocessor,redefine
I have various preprocessor variables which have the same name in different libraries. In order to avoid conflicts, what I am doing is (in the example there is only 1 conflicting variable and 1 header to include for simplicity): #ifdef VAR #define TEMPVAR VAR #undef VAR #endif #include "conflictingheader.hh" #ifdef...

How gets an #if Preprocessor conditional which contains a variable resolved without producing an error?

c++,c,preprocessor
Hi How #if Preprocessor stage statement which contain variable of compile time get resolve at preprocessor stage itself? Below is the code which run without any error: #include<stdio.h> void main() { int num=10; /* compile time */ #if((num%2)==0) /* #if is preprocessor stage but has num of compile time why...

In which situation does this macro can cause an error?

c,macros,preprocessor,c-preprocessor
Consider the following macro #define SQ(x) ((x) * (x)); In which situation does this macro can cause an error?...

noob about css preprocessors workflow - how does it really work?

css,sass,workflow,preprocessor
So, this a very noob question about pre processors. I am a developer and I am trying to understand one thing... how does the css pre processor fit into the day to day design/development workflow? Without it it was something simple like saving the css file and refresh the page....

Pre-Processing using m4

preprocessor,m4
I am writing a pre-processor for Free-Pascal (Course Work) using m4. I was reading the thread at stackoverflow here and from there reached a blog which essentially shows the basic usage of m4 for pre-processing for C. The blogger uses a testing C file test.c.m4 like this: #include define(`DEF', `3')...

How to pass a variable to coffeescript depending on build profile in mimosa

coffeescript,global-variables,preprocessor,mimosa
I have a typical mimosa front-end project with coffeescript for scripting. I want a certain variable (api path) to have different values, depending on build profile (dev or prod). How can I achieve this in mimosa? Example of what I want: prod.coffee: exports.api = 'myserver' dev.coffee: exports.api = 'localhost' api-accessor.coffee...

Run LESS mixin only once

less,preprocessor
I am trying to make sure a mixin that may be called several times in different files, only outputs css once. First try (less) I first was thinking something like this: mixin @_mod: "false"; .mod(@_mod) when (@_mod = "false") { @_mod: "true"; .mod { border-radius: 6px; border: 1px solid...

Adding a preprocessor #define to change which headers are included and witch functions that is called

c++,function,header,preprocessor,multiplatform
So, I'm developing a game engine for Sega Dreamcast and windows, implemented my own library for the Dreamcast hardware which pretty much does the same thing as OpenGL for PC. Now, I want to merge the two builds into one project, so I doesn't need to dev to different project...

Text Preprocessing in Spark-Scala

scala,text,apache-spark,preprocessor,text-mining
I want to apply preprocessing phase on a large amount of text data in Spark-Scala such as Lemmatization - Remove Stop Words(using Tf-Idf) - POS tagging , there is any way to implement them in Spark - Scala ? for example here is one sample of my data: The perfect...

Understanding DEFER and OBSTRUCT macros

c++,c++11,macros,preprocessor,c-preprocessor
I created a small macro metaprogramming library that implements basic useful constructs such as REPEAT(times, x), IF(value, true, false), tuples, and more. Most of my implementations work by overloading macros based upon their variadic argument count or through a counter: // Example: #define REPEAT_0(x) #define REPEAT_1(x) x REPEAT_0(x) #define REPEAT_2(x)...

Create a template header-only project library file

c++,templates,preprocessor
my C++ project is completely based on templates and so my code is splitted in different header files (header-only project). But for the users of the library I want to provide one header file ("library file"), they have to include to use the library. One possibility would be to copy...

Macro Operator List

c++,macros,operators,preprocessor,standard-library
I know about Macro's Stringizing operator (#) and I recently learned about the (##) Concatenation operator: Preprocessor Stringizing Operator with String Literal Prefixes Are there any other macro operators that are available to me? I know that Boost has a pretty extensive suite that they've put together, however for the...

Compare preprocessor macros for equality

c,preprocessor
I have some crude generated header from some .dbc files. Since a few of the messages represent elements from an array the structure is equal and so the generated Macros are equal. Since I fill some array of struct in the code I would like to save effort and use...

How can I replace my c++ exception macro with an inline function with __LINE__ and __FILE__ support?

c++,exception,macros,preprocessor
I currently read the book Effective C++ from Scott Meyers. It says I should prefer inline functions over #define for function-like macros. Now I try to code an inline function to replace my exception macro. My old macro looks like this: #define __EXCEPTION(aMessage) \ { \ std::ostringstream stream; \ stream...

How to escape backslash in // comment

c++,escaping,comments,preprocessor,clang++
I have a comment that ends with backslash. Somethink like ... // use \ .. Clang(++) warned me, that this is multi-line comment warning: multi-line // comment [-Wcomment] // use \ ^ So I try add some whitespace at the end, but didn't help. Can I escape backslash somehow?...

write a simple c preprocessor

c,header,include,preprocessor
I am trying to write a program that immitats the functions of the C preprocessor. So my question is about expanding #include "header.h" statments. I have a FILE * pointer to the source file, so I need to scan for all the header files included in the source file, and...

How to correct below stylus code (Selectors conditional)

css,preprocessor,stylus
How to correct below code in stylus useShortNames = true if useShortNames [class*="mobile-",class*="m-"] else [class*="mobile-"] float: left padding-right: 20px ...

Why when I use #define for int I need to wrap them in brackets?

ios,objective-c,preprocessor
This is my example I've found: #define kNumberOfViews (37) #define kViewsWide (5) #define kViewMargin (2.0) Why it cannot be like that? #define kNumberOfViews 37 #define kViewsWide 5 #define kViewMargin 2.0 And what means k in front? Is there a some guide for it?...

Equivalent to Interfaces in Embbeded C / Code organization

c,architecture,preprocessor,c-preprocessor
I'm developing embedded C code on EFM32 Cortex M3 processors, and after a few months the code is beginning to get crazy... By this I mean that we changed the hardware so we get different versions, on which we changed some components, moved some IOs, have different states for theses...

How to use a processor to dynamically remove/edit properties from views in Extjs

javascript,extjs,preprocessor,post-processor
I have a web application made in sencha extjs 4.0.7, and i want it to have a different behavior when its oppened in a mobile browser. V.G. I would like to remove/edit all the labels in the app based on the mobile browser without have to edit all the application....

Where is the -I (captial i) path relative to in g++?

c++,include,g++,preprocessor,header-files
I am in the App folder of my project. I run the following command to compile character.cpp g++ -Wall -std=c++11 -I../App -c Character/character.cpp -o Obj/character.o which is in App/Character directory. character.cpp has the following include #include "Inventory/inventory.hpp" where the folder of inventory.cpp is App/Inventory. I thought because I am running...

Is it evaluated by precompiler before runtime?

c,preprocessor
I have done this code in order for it to be evaluated by the precompiler before runtime. #define setPinToPortBit(pin)\ if (pin < 19) PORTD ## pin;\ else if(pin>14) PORTB ## (pin-14)\ else PORTC ## (pin - 8) #define STATION1 setPinToPortBit(15) Is there any way to know when will this code...

c++ concatenating macro definitions

c++,macros,concatenation,preprocessor
In C++ (G++ to be specific), can one concatenate two macro definitions, without spaces, to create a 3rd definition? For example, how to I take #define _LOAD _mm256_load #define _FLOAT ps and operate on them thusly #define _LOAD_FLOAT ****do something with _FLOAT and _LOAD here ***** to create a definition...

In c++11 what should happen first: raw string expansion or macros?

c++,c++11,preprocessor,rawstring
This code works in visual c++ 2013 but not in gcc/clang: #if 0 R"foo( #else int dostuff () { return 23; } // )foo"; #endif dostuff(); Visual C++ removes the if 0 first. Clang expands the R raw string first (and never defining dostuff). Who is right and why?...

How to create multiple box-shadows with Stylus function (transpile from Sass)

css,preprocessor,stylus,box-shadow
I found SASS function for "starry sci" creating: // n is number of stars required @function multiple-box-shadow ($n) $value: '#{random(2000)}px #{random(2000)}px #FFF' @for $i from 2 through $n $value: '#{$value} , #{random(2000)}px #{random(2000)}px #FFF' @return unquote($value) #stars{ box-shadow: multiple-box-shadow(700) } I want to transpile it for Stylus, but something doesn't...

C Macro to prefix and suffix a string?

c,macros,preprocessor
I'm trying to clean up my code for colouring strings. Here's what I have to prefix a redansi colour to a string, then suffix it with a reset colour. #define GET_RED_TEXT(x) “\x1B[31m” x “\x1B[00m” However, when I try use it... src/util.c:18:15: error: expected expression char *temp = GET_RED_TEXT("error: "); ^...

win32 logic block preprocessor shows inactive

c++,winapi,logic,visual-studio-2005,preprocessor
i try to use a library on visual studio in differents way by modify its macros on preprocessor directives. However a logic block inside an #if directive is shown to me inactive as it was comment. here is the code: #if defined EBML_DLL #if defined EBML_DLL_EXPORT #define EBML_DLL_API __declspec(dllexport) #else...

How to check a value like “#define VERSION 3.1.4” at compile time?

c++,c++11,preprocessor
I am adding compile-time checks to my company's C++ projects to make sure the third-party libraries on all development machines and build servers are up-to-date. Most libraries define something like the following for e.g. version 3.1.4: #define VERSION_MAJOR 3 #define VERSION_MINOR 1 #define VERSION_BUILD 4 This is nice and easy...

Why is it not advised to define macros in header files?

c++,macros,preprocessor
The Google C++ Style Guide guide advises that macros must not be defined in a .h (header) file. What are the cons of doing it?

Concatenation and the standard

c++,c++11,preprocessor,c-preprocessor
According to this page "A ## operator between any two successive identifiers in the replacement-list runs parameter replacement on the two identifiers". That is, the preprocessor operator ## acts on identifiers. Microsoft's page says ", each occurrence of the token-pasting operator in token-string is removed, and the tokens preceding and...

How to preprocess and compile an assembly file(.s) using gcc?

gcc,assembly,preprocessor
I have a .s file which needs to be preprocessed before compiling it using GCC. Can anyone help me?

What kind of CSS preprocessors is more popular and usable SASS or SCSS? [closed]

css,sass,preprocessor,frontend
I think that SASS is better than SCSS. In SASS not needed to use brackets and have the other good features. What do you think about it? Which of them is better for you?

Is this parenthesis-free C preprocessor definition safe?

c++,c,preprocessor
In my /usr/include directory, there are at least two variants of #define NULL 0 tailored for C++ code1: #define NULL 0 // from rpc/types.h #define NULL (0) // from libio.h I feel like there must be a counter-example where the first one would not be safe, but I was not...

Javascript - Programmatically execute method on input of all functions

javascript,function,methods,preprocessor
I would like to add a parser to a list of functions, for example: var list = { function1: function(input){}, function2: function(input){} } and I would like that all the input params are prepocessed with another function. Is that possible? Any suggestion? Thanks in advance...

Inserting a one-line line comment with a preprocessor macro

c,gcc,macros,preprocessor
Is it possible to simulate a one-line comment (//) using a preprocessor macro (or magic)? For example, can this compile with gcc -std=c99? #define LINE_COMMENT() ??? int main() { LINE_COMMENT() asd(*&#@)($*?><?><":}{)(@ return 0; } ...