From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3264 invoked by alias); 21 Nov 2001 22:36:04 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 3240 invoked by uid 71); 21 Nov 2001 22:36:02 -0000 Date: Fri, 16 Nov 2001 23:56:00 -0000 Message-ID: <20011121223602.3236.qmail@sourceware.cygnus.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Zack Weinberg Subject: Re: preprocessor/4923: Concatenation appears to handle whitespace incorrectly Reply-To: Zack Weinberg X-SW-Source: 2001-11/txt/msg00438.txt.bz2 List-Id: The following reply was made to PR preprocessor/4923; it has been noted by GNATS. From: Zack Weinberg To: s0009525@chelt.ac.uk Cc: gcc-gnats@gcc.gnu.org Subject: Re: preprocessor/4923: Concatenation appears to handle whitespace incorrectly Date: Wed, 21 Nov 2001 09:24:54 -0800 On Wed, Nov 21, 2001 at 04:30:06PM -0000, s0009525@chelt.ac.uk wrote: > #define FOO(x) x > #define BAR FOO(abc) ## def > BAR > > /* cpp < test.h */ > > # 1 "" > abc def This behavior is correct. The concatenation operator acts before the macro FOO is expanded. At that point the tokens on either side of ## are ")" and "def". Pasting them together produces an invalid token, ")def", which triggers undefined behavior - we choose to pretend the ## never happened. Then "FOO ( abc )" gets expanded to produce "abc". Since "abc" and "def" were not concatenated, cpp has to put a space between them so they are interpreted sa separate tokens. gcc 3.x will warn you when this happens: $ cpp-3.0 test.c test.c:5:1: warning: pasting ")" and "def" does not give a valid preprocessing token # 5 "test.c" abc def zw