2012-02-15 2 views
3

컴파일 할 C++ 프로그램을 가져올 수 없습니다. 보시다시피 Node.js addon을 작성하고 있습니다. 내가 선 #include "tbb/concurrent_hash_map.h"을 제거 할 때C++ : 스레드 구성 블록 - 지옥 포함

#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); 
} 

모든 것이 잘 작동 : 여기에 코드 (Eamorr_addon.cpp)입니다. 여기

내 활력 메이크 파일입니다

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

내가 node-gyp build을 할 때, 나는의 바닥에 얻을 수없는 오류 다음 스트림 얻을 :

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 

수있는 사람을 아무것도 제안 해?


편집 :

여기

이다 "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_ */ 

여기가 "Definitions.h"입니다 :

#ifndef DEFINITIONS_H_ 
#define DEFINITIONS_H_ 

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


#endif /* DEFINITIONS_H_ */ 
매크로는 사용하기 쉽고
+1

파일 제대로 종료 "Rk.h"의 마지막 선언입니다 즉, 세미콜론이 누락되지 않았습니까?) –

+0

당신은 분명히 거기에 있습니다. Rk.h와 Definitions.h를 주석 처리하면 컴파일이 잘된 것처럼 보입니다! 지금 조사 중입니다. – Eamorr

+0

@ JoachimPileborg 안녕하세요, 요아킴 - 제 편집을 좀 볼 수 있을까요? 두 개의 include 파일을 게시했습니다. 나는 아직도 문제를 발견하지 못한다. 많은 감사합니다, – Eamorr

답변

9

#define 잘못된. D과 같은 이름을 지정하면 문제가 발생합니다. 우리가 atomic.h 보면

당신은 지금

#define D 2 

D 정의, 우리는 예를 들어, 발견

... 
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)); 
    } 
... 

상관 관계를 참조 하시겠습니까?

는 당신이 얻을 것은 :

... 
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)); 
    } 
... 

이것은 ++ 유효 C 없습니다.

해결 방법 : 매크로에 충돌이 발생할 수있는 이름을 지정하지 마십시오. 엄지 손가락의 규칙 : 모든 깔끔한 이름은 일생에 적어도 한 번 이상 충돌하고 가난한 관리자 (당신?) 야간 드라론 형언 할 수없는 악마의 비전으로 꿈꾸는 미묘하고 비현실적인 오류 메시지를 생성합니다. 따라서 반드시 사용해야하는 경우에만 매크로를 사용하십시오. D 만약

이 정수 있어야 (하지만 누가, 당신을 제외하고, 그 이름을 아는 사람?), 당신은 다음 중 하나를 수행 할 수 있습니다 :

enum { D = 2 }; 

또는

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

또는 D가 일정해야 할 필요가 있는지 여부를 결정하고 대신 함수 및 클래스의 매개 변수로 전달할 것인지 결정할 수 있습니다.

1

다음은 tbb/atomic에서 발췌 한 것입니다.이제 시간

 

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))); 
    } 
... 
 

, D위한 대체 정의 Definitions.h에서 당신은 문제가 무엇인지 볼 경우. 일반적으로 그런 이름을 가진 매크로 정의를 만드는 것은 나쁜 생각입니다. 당신이 D에 따라 너무 많은 코드를 가지고 있다면 당신은 TBB 헤더, 같은 것을 포함을 befor를 정의 해제하여 문제를 해결할 수 있습니다 : (

 

#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") 
 
+0

이 경우 그는 코드가별로 없습니다. C++에 대한 컴파일러 관련 확장 기능 및 확장 불가능한 확장 기능을 제안하는 것은 올바른 일이 아닙니다. –

+0

@phresnel : 그가 가진 매크로 인'D'에 따라 얼마나 많은 코드가 있는지 어떻게 알 수 있습니까? 그리고 그가 신인인지 아닌지는 모르지만, 기본적으로 그는 그렇지 않다고 생각합니다. 또한 컴파일러와 관련된 컴파일러가 아닙니다.이 플러그인은 적어도 GCC, MSVC 및 ICC에서 지원됩니다. 아무튼, 해결책은 하나의 특정 경우에만 (너무 많은 코드에 따라이 매크로에 따라) 제안되었으며, 명확하게 내 대답에 명시된 것처럼 보입니다. –

+0

네 말이 맞아, 나는 실수로 그 코드가 거의 전부라고 생각했다. ' 그러나, 소프트웨어를 다시 엔지니어링 할 때 더 나은 휴대용 대안 (enum, const, 전역 상수를 사용하지 않음)이있을 때 이러한 확장을 사용하지 않아도된다고 생각합니다 (코드 워리어, clang ++, openwatcom 등). 모든). 제안서의 크기가 조정되지 않습니다 (D를 언급하는 파일을 포함하는 모든 파일에 푸시/팝을 넣어야합니다. 이름이 _now_와 충돌하는 각 매크로에 대해이 프로세스를 반복해야합니다. 그런 다음 푸시/팝을 확인해야합니다. 각 include 파일의 새 버전 용). ... –