From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2013 invoked by alias); 5 Apr 2010 21:00:59 -0000 Received: (qmail 1992 invoked by uid 22791); 5 Apr 2010 21:00:57 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=BAYES_00,SARE_MSGID_LONG45,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fork9.mail.Virginia.EDU (HELO fork9.mail.virginia.edu) (128.143.2.179) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Apr 2010 21:00:52 +0000 Received: from localhost (localhost [127.0.0.1]) by fork9.mail.virginia.edu (Postfix) with ESMTP id D45C41F5289 for ; Mon, 5 Apr 2010 17:00:49 -0400 (EDT) Received: from fork9.mail.virginia.edu ([127.0.0.1]) by localhost (fork9.mail.virginia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 21006-03 for ; Mon, 5 Apr 2010 17:00:49 -0400 (EDT) Received: from mail-pw0-f49.google.com (mail-pw0-f49.google.com [209.85.160.49]) by fork9.mail.virginia.edu (Postfix) with ESMTP id 884EE1F5209 for ; Mon, 5 Apr 2010 17:00:49 -0400 (EDT) Received: by mail-pw0-f49.google.com with SMTP id 3so2553857pwj.36 for ; Mon, 05 Apr 2010 14:00:49 -0700 (PDT) Received: by 10.140.55.9 with SMTP id d9mr4443926rva.94.1270501247346; Mon, 05 Apr 2010 14:00:47 -0700 (PDT) Received: from mail-pw0-f49.google.com (mail-pw0-f49.google.com [209.85.160.49]) by mx.google.com with ESMTPS id 21sm2140676pzk.8.2010.04.05.14.00.45 (version=SSLv3 cipher=RC4-MD5); Mon, 05 Apr 2010 14:00:45 -0700 (PDT) Received: by pwj3 with SMTP id 3so2642872pwj.36 for ; Mon, 05 Apr 2010 14:00:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.114.77.3 with HTTP; Mon, 5 Apr 2010 14:00:06 -0700 (PDT) From: Liu Liu Date: Mon, 05 Apr 2010 21:00:00 -0000 Received: by 10.115.102.20 with SMTP id e20mr5385228wam.194.1270501226372; Mon, 05 Apr 2010 14:00:26 -0700 (PDT) Message-ID: Subject: the problem about different treatment to __VA_ARGS__ when using VS 2008 and GCC To: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-UVA-Virus-Scanned: by amavisd-new at fork9.mail.virginia.edu X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2010-04/txt/msg00022.txt.bz2 Hi, I am trying to identify a problem because of an unusual usage of variadic macros. Here is the hypothetic macro: #define va(c, d, ...) c(d, __VA_ARGS__) #define var(a, b, ...) va(__VA_ARGS__, a, b) var(2, 3, printf, =93%d %d %d\n=94, 1); For gcc, the preprocessor will output printf("%d %d %d\n", 1, 2, 3) but for VS 2008, the output is printf, =93%d %d %d\n=94, 1(2, 3); I suspect the difference is caused by the different treatment to __VA_ARGS__, for gcc, it will first expand the expression to va(printf, "%d %d %d\n", 1, 2, 3), and treat 1, 2, 3 as the __VA_ARGS__ for macro va. But for VS 2008, it will first treat b as __VA_ARGS__ for macro va, and then do the expansion. Which one is correct interpretation for C99 variadic macro? or my usage falls into an undefined behavior? Thank you. -- Liu Liu +1 650 521 3058 http://liuliu.me/ http://www.cs.virginia.edu/~ll2ef/