[완료]g++컴파일에러(함수형 마크로 호출시 에러)

hseong의 이미지

고수님들 갈켜주세염...
원인과 해결방안이......

현상
솔라리스에서는 문제없이 컴파일이 됩니다만 리눅스(아래의 버젼 참조)상에서
컴파일에러가 나타납니다.
다른 정보에 의하면 gcc 2.X에서는 별문제없이 컴파일이 되지만
버젼이3.X이상에서는 아래와같은 컴파일에러가 나옵니다라고......

질문
컴파일러 버젼 문제인가여?
해결방안으로 패치는 있는가여?
(소스는 수정없이 ...)

에러메세지:
define_test.c:38:1: pasting "_test" and "(" does not give a valid preprocessing token
커널:Red Hat Enterprise Linux AS release 4 (Nahant)
컴파일러:g++ (GCC) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)

-- 이하 소스 --
#include
#include

#define SEND4(o, m, l, on_off) o->send_extr_indir(o->_##m##l, on_off)

class Define
{
public:
int send_extr_indir(int data1, int data2);
int _test(int arg1, int arg2);
int test(void);
};

int Define::send_extr_indir(int data1, int data2)
{
printf("data1=%d\n", data1);
printf("data2=%d\n", data2);

return data1+data2;
}

int Define::_test(int arg1, int arg2)
{
return arg1 + arg2;
}

int Define::test(void)
{
return SEND4(this,
test,
(1,2),
5
);
}

int main(void)
{
int result = 0;
Define object;
result = object.test();
printf("result=%d\n", result);

return 0;
}

익명 사용자의 이미지

-E 옵션으로 preprocessing 결과만 확인해 보세요.

hseong의 이미지

-E 옵션으로 preprocessing 결과를 확인해봤는데요.

결과적으로는 변환처리는 제대로 하는데,
에러메세지를 출력하네요.
에러메세지가 출력되지 않게 하는 방법은 없나요?

-- 이하 결과 --
<-- 생략 -->
class Define
{
public:
int send_extr_indir(int data1, int data2);
int _test(int arg1, int arg2);
int test(void);
};

int Define::send_extr_indir(int data1, int data2)
{
printf("data1=%d\n", data1);
printf("data2=%d\n", data2);

return data1+data2;
}

int Define::_test(int arg1, int arg2)
{
return arg1 + arg2;
}

int Define::test(void)
{
macro_test.c:34:1: pasting "_test" and "(" does not give a valid preprocessing token
return this->send_extr_indir(this->_test(1,2), 5);

}

int main(void)
{
int result = 0;
Define object;
result = object.test();
printf("result=%d\n", result);

return 0;
}

jick의 이미지

## 연산자는 앞뒤의 토큰을 합쳐서 하나의 토큰을 만들어주는 연산자입니다. 따라서 앞뒤의 토큰을 합쳐도 하나의 토큰이 되지 않는 경우는 엄밀히 말해 잘못된 사용법인 걸로 알고 있습니다. (이게 표준에선 되는데 g++에서 안되는 건지 표준에서도 안되는 건지는 잘 모르겠네요...)

이 경우 두번째 ## 연산자는 에러만 발생시키고 사실상 하는 기능이 없으니 빼버리시면 될 것 같네요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.