c 매크로 기능에 대해서 여쭤 보겠습니다.

metalwolf의 이미지

다름이 아니라 VC++ 6.0은 되는데 g++에서는 안되는 군요.

예전엔 되었다고 생각했는데..

#include <stdio.h>

#define Log(x) printf(x)

int main(void)
{
int nTest = 0;
int nTest2 = 3;
Log("Test[%d][%d]\n",nTest,nTest2 );

return 0;
}

위와 같이 printf를 Log로 define 하면 vc++ 6.0에는 경고를
내더라도 컴파일이 되고 잘 작동 되는데

g++에서는 되지 않군요.

에러는 다음과 같습니다.

macro_test.cpp:12:19: macro "Log" passed 2 arguments, but takes just 1
macro_test.cpp: In function `int main()':
macro_test.cpp:12: error: `Log' undeclared (first use this function)
macro_test.cpp:12: error: (Each undeclared identifier is reported only once for each function it appears in.)

컴파일러 버젼은 gcc 3.4.4 입니다.

혹시 아시는 분 있으시면 답변 주시면 감사하겠습니다. ^^;

익명 사용자의 이미지

가변인자 매크로에 대해서는 C95까지의 표준에 정해진 바가 없기 때문에, 각 구현체의 특성을 이용한 핵을 사용하거나 혹은 각각의 확장을 사용하는 예가 많습니다.

gcc 3.4.4 라면 아마도 C99에서 정의된 다음과 같은 형식의 가변인자 매크로가 사용 가능할 것입니다.

#define debug(...) fprintf(stderr, _ _VA_ARGS_ _)
#define showlist(...) puts(#_ _VA_ARGS_ _)
#define report(test, ...) ((test)?puts(#test):\
printf(_ _VA_ARGS_ _))
debug("Flag");
debug("X = %d\n", x);
showlist(The first, second, and third items.);
report(x>y, "x is %d but y is %d", x, y);

Visual C++ 6.0에서는 아마 안될 듯하고, Visual Studio 2005 에서는 될것 같지만 확실히는 모르겠습니다.

체스맨의 이미지

최근 표준 안쓰고 모든 컴파일러에서 잘 되게 하는 방법도 있습니다.

http://bbs.kldp.org/viewtopic.php?t=65565

Orion Project : http://orionids.org

metalwolf의 이미지

답변 감사드립니다. 정규 규격 외에

Log(x...) printf(x)

하니까 컴파일 되네요.

답변 정말 감사 드려요.^^;

^____^; 방가여

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.