3

I can't get my C++ program to compile. As you can see, I'm writing a Node.js addon. Here is the code (Eamorr_addon.cpp):

#include <iostream>
#include <v8.h>
#include <node.h>
#include <gmp.h>

#include "Definitions.h"
#include "Rk.h"

#include "tbb/concurrent_hash_map.h"
//#include <tbb/concurrent_vector.h>

using namespace std;
using namespace v8;



static Handle<Value> Echo(const Arguments& args) {
    HandleScope scope;

    if (args.Length() < 1) {
        return ThrowException(Exception::TypeError(String::New("Bad argument")));
    }

    return scope.Close(args[0]);
}

extern "C" void init (Handle<Object> target)
{
    HandleScope scope;
    target->Set(String::New("hello"), String::New("world"));

    NODE_SET_METHOD(target, "echo", Echo);
}

Everything works just fine when I remove the line #include "tbb/concurrent_hash_map.h".

Here is my gyp make file:

{
  'targets': [
    {
      'target_name':'Eamorr_addon',
      'sources':['src/Eamorr_addon.cpp'],
      'include_dirs': ['/usr/include','/usr/local/include/'],
      'cflags': ['-Wall','-fopenmp'],
      'ldflags': ['-ltbb','-lgmp']
    }
  ]
}

When I do node-gyp build, I get the following stream of errors which I can't get to the bottom of:

node-gyp build
info it worked if it ends with ok 
spawn make [ 'BUILDTYPE=Release', '-f', 'Makefile.gyp' ]
  CXX(target) out/Release/obj.target/DeDuplicator_addon/src/DeDuplicator_addon.o
In file included from /usr/include/tbb/concurrent_hash_map.h:51:0,
                 from src/DeDuplicator_addon.cpp:17:
/usr/include/tbb/atomic.h:218:31: error: expected nested-name-specifier before numeric constant
/usr/include/tbb/atomic.h:218:31: error: expected ‘>’ before numeric constant
/usr/include/tbb/atomic.h:224:33: error: expected ‘)’ before ‘addend’
/usr/include/tbb/atomic.h:224:40: error: ISO C++ forbids initialization of member ‘fetch_and_add’
/usr/include/tbb/atomic.h:224:40: error: making ‘fetch_and_add’ static
/usr/include/tbb/atomic.h:224:40: error: template declaration of ‘value_type tbb::internal::fetch_and_add’
In file included from /usr/include/tbb/concurrent_hash_map.h:51:0,
                 from src/DeDuplicator_addon.cpp:17:
/usr/include/tbb/atomic.h:228:31: error: expected identifier before numeric constant
/usr/include/tbb/atomic.h:228:31: error: expected ‘,’ or ‘...’ before numeric constant
/usr/include/tbb/atomic.h:251:28: error: expected identifier before numeric constant
/usr/include/tbb/atomic.h:251:28: error: expected ‘,’ or ‘...’ before numeric constant
/usr/include/tbb/atomic.h:255:28: error: expected identifier before numeric constant
/usr/include/tbb/atomic.h:255:28: error: expected ‘,’ or ‘...’ before numeric constant
/usr/include/tbb/atomic.h: In member function ‘value_type tbb::internal::atomic_impl_with_arithmetic<I, <anonymous> >::fetch_and_add(int)’:
/usr/include/tbb/atomic.h:229:48: error: ‘addend’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘value_type tbb::internal::atomic_impl_with_arithmetic<I, <anonymous> >::fetch_and_decrement()’:
/usr/include/tbb/atomic.h:243:33: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h:243:33: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h:243:33: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h: In member function ‘value_type tbb::internal::atomic_impl_with_arithmetic<I, <anonymous> >::fetch_and_decrement()’:
/usr/include/tbb/atomic.h:247:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h:247:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h:247:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h: In member function ‘value_type tbb::internal::atomic_impl_with_arithmetic<I, <anonymous> >::operator+=(int)’:
/usr/include/tbb/atomic.h:252:30: error: ‘addend’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘value_type tbb::internal::atomic_impl_with_arithmetic<I, <anonymous> >::operator-=(int)’:
/usr/include/tbb/atomic.h:258:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h:258:32: error: ‘addend’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘value_type tbb::internal::atomic_impl_with_arithmetic<I, <anonymous> >::operator--()’:
/usr/include/tbb/atomic.h:266:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h:266:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h:266:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h: In member function ‘value_type tbb::internal::atomic_impl_with_arithmetic<I, <anonymous> >::operator--(int)’:
/usr/include/tbb/atomic.h:274:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h:274:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h:274:30: error: ‘2’ cannot be used as a function
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:329:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘long long int tbb::atomic<long long int>::operator=(long long int)’:
/usr/include/tbb/atomic.h:329:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<long long int>& tbb::atomic<long long int>::operator=(const tbb::atomic<long long int>&)’:
/usr/include/tbb/atomic.h:329:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:330:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘long long unsigned int tbb::atomic<long long unsigned int>::operator=(long long unsigned int)’:
/usr/include/tbb/atomic.h:330:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<long long unsigned int>& tbb::atomic<long long unsigned int>::operator=(const tbb::atomic<long long unsigned int>&)’:
/usr/include/tbb/atomic.h:330:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:335:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘long int tbb::atomic<long int>::operator=(long int)’:
/usr/include/tbb/atomic.h:335:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<long int>& tbb::atomic<long int>::operator=(const tbb::atomic<long int>&)’:
/usr/include/tbb/atomic.h:335:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:336:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘long unsigned int tbb::atomic<long unsigned int>::operator=(long unsigned int)’:
/usr/include/tbb/atomic.h:336:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<long unsigned int>& tbb::atomic<long unsigned int>::operator=(const tbb::atomic<long unsigned int>&)’:
/usr/include/tbb/atomic.h:336:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:352:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘unsigned int tbb::atomic<unsigned int>::operator=(unsigned int)’:
/usr/include/tbb/atomic.h:352:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<unsigned int>& tbb::atomic<unsigned int>::operator=(const tbb::atomic<unsigned int>&)’:
/usr/include/tbb/atomic.h:352:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:353:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘int tbb::atomic<int>::operator=(int)’:
/usr/include/tbb/atomic.h:353:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<int>& tbb::atomic<int>::operator=(const tbb::atomic<int>&)’:
/usr/include/tbb/atomic.h:353:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:356:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘short unsigned int tbb::atomic<short unsigned int>::operator=(short unsigned int)’:
/usr/include/tbb/atomic.h:356:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<short unsigned int>& tbb::atomic<short unsigned int>::operator=(const tbb::atomic<short unsigned int>&)’:
/usr/include/tbb/atomic.h:356:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:357:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘short int tbb::atomic<short int>::operator=(short int)’:
/usr/include/tbb/atomic.h:357:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<short int>& tbb::atomic<short int>::operator=(const tbb::atomic<short int>&)’:
/usr/include/tbb/atomic.h:357:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:358:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘char tbb::atomic<char>::operator=(char)’:
/usr/include/tbb/atomic.h:358:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<char>& tbb::atomic<char>::operator=(const tbb::atomic<char>&)’:
/usr/include/tbb/atomic.h:358:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:359:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘signed char tbb::atomic<signed char>::operator=(signed char)’:
/usr/include/tbb/atomic.h:359:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<signed char>& tbb::atomic<signed char>::operator=(const tbb::atomic<signed char>&)’:
/usr/include/tbb/atomic.h:359:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:360:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘unsigned char tbb::atomic<unsigned char>::operator=(unsigned char)’:
/usr/include/tbb/atomic.h:360:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<unsigned char>& tbb::atomic<unsigned char>::operator=(const tbb::atomic<unsigned char>&)’:
/usr/include/tbb/atomic.h:360:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:363:1: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
/usr/include/tbb/atomic.h: In member function ‘wchar_t tbb::atomic<wchar_t>::operator=(wchar_t)’:
/usr/include/tbb/atomic.h:363:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: In member function ‘tbb::atomic<wchar_t>& tbb::atomic<wchar_t>::operator=(const tbb::atomic<wchar_t>&)’:
/usr/include/tbb/atomic.h:363:1: error: ‘store_with_release’ was not declared in this scope
/usr/include/tbb/atomic.h: At global scope:
/usr/include/tbb/atomic.h:367:93: error: wrong number of template arguments (3, should be 2)
/usr/include/tbb/atomic.h:219:8: error: provided for ‘template<class I, int <anonymous> > struct tbb::internal::atomic_impl_with_arithmetic’
In file included from src/DeDuplicator_addon.cpp:17:0:
/usr/include/tbb/concurrent_hash_map.h: In member function ‘bool tbb::interface4::internal::hash_map_base::check_mask_race(tbb::interface4::internal::hash_map_base::hashcode_t, tbb::interface4::internal::hash_map_base::hashcode_t&) const’:
/usr/include/tbb/concurrent_hash_map.h:266:21: error: cannot convert ‘const tbb::atomic<long unsigned int>’ to ‘tbb::interface4::internal::hash_map_base::hashcode_t’ in assignment
/usr/include/tbb/concurrent_hash_map.h: In member function ‘tbb::interface4::internal::hash_map_base::segment_index_t tbb::interface4::internal::hash_map_base::insert_new_node(tbb::interface4::internal::hash_map_base::bucket*, tbb::interface4::internal::hash_map_base::node_base*, tbb::interface4::internal::hash_map_base::hashcode_t)’:
/usr/include/tbb/concurrent_hash_map.h:296:30: error: no match for ‘operator++’ in ‘++((tbb::interface4::internal::hash_map_base*)this)->tbb::interface4::internal::hash_map_base::my_size’
/usr/include/tbb/concurrent_hash_map.h: In member function ‘void tbb::interface4::internal::hash_map_base::reserve(tbb::interface4::internal::hash_map_base::size_type)’:
/usr/include/tbb/concurrent_hash_map.h:316:32: error: no match for ‘operator!’ in ‘!((tbb::interface4::internal::hash_map_base*)this)->tbb::interface4::internal::hash_map_base::my_size’
/usr/include/tbb/concurrent_hash_map.h:316:32: note: candidate is: operator!(bool) <built-in>
/usr/include/tbb/concurrent_hash_map.h:317:32: error: cannot convert ‘tbb::atomic<long unsigned int>’ to ‘tbb::interface4::internal::hash_map_base::size_type’ in initialization
/usr/include/tbb/concurrent_hash_map.h:317:58: error: cannot convert ‘tbb::atomic<long unsigned int>’ to ‘tbb::interface4::internal::hash_map_base::size_type’ in assignment
/usr/include/tbb/concurrent_hash_map.h: In member function ‘bool tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>::empty() const’:
/usr/include/tbb/concurrent_hash_map.h:833:44: error: no match for ‘operator==’ in ‘((const tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>*)this)->tbb::interface4::internal::hash_map_base::my_size == 0’
/usr/include/tbb/concurrent_hash_map.h: In member function ‘tbb::interface4::concurrent_hash_map::size_type tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>::bucket_count() const’:
/usr/include/tbb/concurrent_hash_map.h:839:53: error: no match for ‘operator+’ in ‘((const tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>*)this)->tbb::interface4::internal::hash_map_base::my_mask + 1’
/usr/include/tbb/concurrent_hash_map.h: In member function ‘bool tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>::exclude(tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>::const_accessor&, bool)’:
/usr/include/tbb/concurrent_hash_map.h:1119:16: error: no ‘operator--(int)’ declared for postfix ‘--’
/usr/include/tbb/concurrent_hash_map.h: In member function ‘bool tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>::erase(const Key&)’:
/usr/include/tbb/concurrent_hash_map.h:1160:16: error: no ‘operator--(int)’ declared for postfix ‘--’
/usr/include/tbb/concurrent_hash_map.h: In member function ‘void tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>::internal_copy(const tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>&)’:
/usr/include/tbb/concurrent_hash_map.h:1310:20: error: no match for ‘operator==’ in ‘((tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>*)this)->tbb::interface4::internal::hash_map_base::my_mask == mask’
/usr/include/tbb/concurrent_hash_map.h:1323:19: error: no match for ‘operator++’ in ‘++((tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>*)this)->tbb::interface4::internal::hash_map_base::my_size’
/usr/include/tbb/concurrent_hash_map.h: In member function ‘void tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>::internal_copy(I, I)’:
/usr/include/tbb/concurrent_hash_map.h:1340:11: error: no match for ‘operator++’ in ‘++((tbb::interface4::concurrent_hash_map<Key, T, HashCompare, A>*)this)->tbb::interface4::internal::hash_map_base::my_size’
make: *** [out/Release/obj.target/DeDuplicator_addon/src/DeDuplicator_addon.o] Error 1
ERR! Error: `make` failed with exit code: 2
    at Array.0 (/usr/local/lib/node_modules/node-gyp/lib/build.js:118:25)
    at EventEmitter._tickCallback (node.js:192:40)
ERR! not ok

Can anyone suggest anything?


Edit:

Here is "Rk.h":

#ifndef RK_H_
#define RK_H_

#include <gmp.h>
#include "Definitions.h"

unsigned long int init_rkHash(char* str);
unsigned long int get_rkHash(unsigned long int prevHash,int prevAscii,int topAscii);
/*unsigned long int getFirstPrevHash(char* &buffer);*/

#endif /* RK_H_ */

and here is "Definitions.h":

#ifndef DEFINITIONS_H_
#define DEFINITIONS_H_

#define PORT 10002
#define CHUNKSIZE 512
#define PRIME 9223372036854775783
#define D 2


#endif /* DEFINITIONS_H_ */
Eamorr
  • 9,308
  • 32
  • 117
  • 200
  • 1
    Is the last declaration in the file "Rk.h" properly terminated (i.e. not missing a semicolon)? – Some programmer dude Feb 15 '12 at 10:53
  • You're definitely on to something there. When I comment out Rk.h and Definitions.h it appears to compile just fine! Investigating now. – Eamorr Feb 15 '12 at 10:56
  • @JoachimPileborg Hey Joachim - I wonder could you take a look at my edit? I've posted the two include files. I still don't spot the problem. Many thanks, – Eamorr Feb 15 '12 at 11:04
  • @Eamorr: Even though you explicitly requested Joachim to provide an answer, I took the liberty to inspect your code, too. Is that okay for you? – Sebastian Mach Feb 15 '12 at 11:52

2 Answers2

9

#define macros are easy to use wrong. And giving them names like D calls for problems.

You defined D as

#define D 2

Now, if we look at atomic.h, we find e.g.

...
template<typename I, typename D, typename StepType>
struct atomic_impl_with_arithmetic: atomic_impl<I> {
...
    value_type fetch_and_add( D addend ) {
...
    template<memory_semantics M>
    value_type fetch_and_decrement() {
        return fetch_and_add<M>(__TBB_MINUS_ONE(D));
    }
...

See the correlation?

What you get is:

...
template<typename I, typename 2, typename StepType>
struct atomic_impl_with_arithmetic: atomic_impl<I> {
...
    value_type fetch_and_add( 2 addend ) {
...
    template<memory_semantics M>
    value_type fetch_and_decrement() {
        return fetch_and_add<M>(__TBB_MINUS_ONE(2));
    }
...

This is not valid C++.

Solution: Don't give macros a name that will probably clash. Rule of thumb: Every neat name clashes at least once in a lifetime and produce subtle and unreal error messages that might infect a poor maintainers (you?) nightly dreams with visions of indescribable demons. Therefore, only use macros if you absolutely must.

If D is supposed to be an integer (but who, except you, knows by that name?), you can do one of the following:

enum { D = 2 };

or

extern const int D; // in a header
const int D = 2; // in exactly one source file

or you may rethink your decision whether D needs to be constant at all and instead pass it as a parameter to your functions and classes.

Sebastian Mach
  • 36,158
  • 4
  • 87
  • 126
1

Here is an excerpt from tbb/atomic.h


template<typename I, typename D, typename StepType>
struct atomic_impl_with_arithmetic: atomic_impl<I> {
public:
    typedef I value_type;

    template<memory_semantics M>
    value_type fetch_and_add( D addend ) {
         return value_type(internal::atomic_traits<sizeof(value_type),M>::fetch_and_add( &this->rep.value, addend*sizeof(StepType) ));
    }
...

Now, if you substitute definition for D from Definitions.h you'll see what the issue is. In general it's a bad idea to make macro definitions with such names. If you've got too much code dependent on D you can fix the issue by undefining it befor including tbb headers, something like this:


#include "Definitions.h"
#include "Rk.h"

#pragma push_macro("D")
#undef D

#include "tbb/concurrent_hash_map.h"
#include <tbb/concurrent_vector.h>

#pragma pop_macro("D")

Konstantin Oznobihin
  • 4,996
  • 20
  • 31
  • In this case, he won't have much code. Proposing compiler specific and non-scalable extensions to a C++-newcomer is not the right thing to do. – Sebastian Mach Feb 15 '12 at 12:05
  • @phresnel: How do you know how much code depending on `D` being a macro he has? And I don't know if he is a newcomer or not, by default I suppose he is not. Also, it's not really that much compiler specific, this pragma is supported by at least GCC, MSVC and ICC. Anyhow, the solution was proposed for one specific case only (too much code depending on this macro to be changed), and it looks like it was clearly enough specified in my answer. – Konstantin Oznobihin Feb 15 '12 at 12:39
  • You are right, I mistakenly assumed that the shown code is almost all of his'. However, when re-engineering software, I don't think you should use such extensions (have you also checked codewarrior, clang++, openwatcom, ...) when better, portable alternatives are there (enum, const, not using global constants at all). Your proposal does not scale (you have to put those push/pop into all files that include a file that mentions D, then you have to repeat that process for each macro whose name clashes _now_, and then you have to verify those push/pop for newer versions of each include file). ... – Sebastian Mach Feb 15 '12 at 13:27
  • ... if anything, this is just an interim solution between two commits into version-control that should not make it into version-control, but it is not a "fix" as you describe, as this solution is just temporary and highly subject to regression. – Sebastian Mach Feb 15 '12 at 13:29
  • It's arguable if it is subject to regression, more probably it is not, since existing code is leaved as is. When you need to make changes in large legacy code base right now (or even earlier), the least intrusive approach might be preferrable even if not most beautiful one. – Konstantin Oznobihin Feb 15 '12 at 14:59
  • `existing code is leaved as is`: That's speculation on _your_ side this time. Also, on a well set up box, `` is subject to change, so you better push/pop _all_ macros. That's equally true for all 3rd party include files, not only TBB. – Sebastian Mach Feb 15 '12 at 15:14
  • why speculation? If you don't change `D` to be not macro you don't have to change existing code. Adding TBB usage is surely a change, but it's out of scope of this discussion. – Konstantin Oznobihin Feb 15 '12 at 15:23
  • the problem was: system/library headers are always subject to change. therefore, you not only have to fix `D`, but also `PORT`, `CHUNKSIZE`, etc., because you don't know if those identifiers (tokenization parlance) are ever used – Sebastian Mach Feb 15 '12 at 15:29