From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24860 invoked by alias); 15 Aug 2008 20:39:38 -0000 Received: (qmail 24843 invoked by uid 22791); 15 Aug 2008 20:39:37 -0000 X-Spam-Check-By: sourceware.org Received: from perm68-235.ij.net (HELO smirk.3gfp.com) (209.216.68.235) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 15 Aug 2008 20:38:54 +0000 Received: from localhost (localhost [127.0.0.1]) by smirk.3gfp.com (Postfix) with ESMTP id 08A5C9B04C1 for ; Fri, 15 Aug 2008 16:38:52 -0400 (EDT) Received: from smirk.3gfp.com ([127.0.0.1]) by localhost (smirk.3gfp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ZVslaqyCrMaf for ; Fri, 15 Aug 2008 16:38:50 -0400 (EDT) Received: from harveybook.swlocal (64-132-158-194.static.twtelecom.net [64.132.158.194]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smirk.3gfp.com (Postfix) with ESMTP id 5D9B19B042E for ; Fri, 15 Aug 2008 16:38:50 -0400 (EDT) Message-ID: <48A5E959.6050505@3gfp.com> Date: Sat, 16 Aug 2008 11:38:00 -0000 From: Richard Harvey Chapman User-Agent: Thunderbird 2.0.0.16 (Macintosh/20080707) MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Macro question regarding single quotes Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 2008-08/txt/msg00153.txt.bz2 I'd like to shorten-up so redundant code in a switch statement by using a macro for each case. The following code illustrates the problem. In short, is there a way to write the PARSE(a,b) macro that will work in the manner shown below? Thanks, H. ======== #include int varAB = 1; int varFG = 2; #define TEST1(a,b) printf("'%c' '%c' = %d\n", *#a, *#b, var##a##b) #define TEST2(a,b) printf("'%c' '%c' = %d\n", #a[0], #b[0], var##a##b) int ParseAB(void) { return(0); } int ParseCD(void) { return(0); } int ParseEF(void) { return(0); } // * not allowed in case statement #define PARSE(a,b) case (*#a << 8) | *#b: \ status = Parse##a##b(); \ break // ends up being literally 'a' and 'b' #define PARSE2(a,b) case ('a' << 8) | 'b': \ status = Parse##a##b(); \ break int main() { int status = 0; TEST1(A,B); TEST2(F,G); switch (('A' << 8) | 'B') { // This is what the output of the PARSE macro should be: case ('A' << 8) | 'B': status = ParseAB(); break; // This is how I'd like to use the macro. PARSE(C,D); PARSE(E,F); default: status = -1; } return(0); }