From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12354 invoked by alias); 26 Jan 2008 22:16:31 -0000 Received: (qmail 12343 invoked by uid 22791); 26 Jan 2008 22:16:30 -0000 X-Spam-Check-By: sourceware.org Received: from mercutio.sslaccess.com (HELO mercutio.sslaccess.com) (202.125.33.16) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 26 Jan 2008 22:16:03 +0000 Received: by mercutio.sslaccess.com (Postfix, from userid 1001) id 01BB33A4089; Sun, 27 Jan 2008 08:11:34 +1000 (EST) Received: from mail3.sslaccess.com (mail3.sslaccess.com [202.125.33.7]) by mercutio.sslaccess.com (Postfix) with SMTP id 882D83A406B for ; Sun, 27 Jan 2008 08:11:34 +1000 (EST) Received: (qmail 18237 invoked from network); 26 Jan 2008 22:15:58 -0000 Received: from unknown (HELO sid6170.sslaccess.com) (202.125.32.187) by titan.ozservers.com.au with SMTP; 26 Jan 2008 22:15:58 -0000 Received: (qmail 17918 invoked from network); 27 Jan 2008 08:15:58 +1000 Received: from cust0701.vic01.dataco.com.au (HELO DEVELOPMENT) (202.63.38.189) by sid6170.sslaccess.com with SMTP; 27 Jan 2008 08:15:58 +1000 From: "Ron Kreymborg" To: Subject: Mangle functions Date: Mon, 28 Jan 2008 10:22:00 -0000 Message-ID: <000501c86069$07d63310$17829930$@com.au> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Content-Language: en-au x-cr-hashedpuzzle: BSXk ChTC DxHu EoBS EyfG GPDZ HAkO Htgp Jpjm Jqrb J2AF Kcfq K3Mq Lypa MSYi Mwr3;1;ZwBjAGMALQBoAGUAbABwAEAAZwBjAGMALgBnAG4AdQAuAG8AcgBnAA==;Sosha1_v1;7;{ECAC86FB-97A6-40F9-B095-2340FABD62EF};cgBvAG4AQABqAGUAbgBuAGEAcgBvAG4ALgBjAG8AbQAuAGEAdQA=;Sat, 26 Jan 2008 22:15:02 GMT;TQBhAG4AZwBsAGUAIABmAHUAbgBjAHQAaQBvAG4AcwA= x-cr-puzzleid: {ECAC86FB-97A6-40F9-B095-2340FABD62EF} 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-01/txt/msg00276.txt.bz2 Is there a way the C++ pre-processor can access the mangled name of a class method? This would greatly simplify implementing interrupt handlers as private class methods in embedded systems where the processor uses an interrupt vector table. Currently one must manually build the mangled name and pass it to the gcc "alias" attribute. My idea is a macro like: #define CLASS_ISR(theclassname, themethodname) \ ISR(theclassname) ISR_ALIASOF(gcc_mangle(theclassname, themethodname)); \ void theclassname::themethodname(void) where the "gcc_mangle" function is what I am after. If this existed it would allow automating the creation of classes for embedded systems where the interrupt handler is a private class method and its "friend" status allows it access to the class data of the owning device manager class. The abbreviated example class definitions below show the timer overflow interrupt handler for the Timer0 peripheral of an Atmel AVR microprocessor: //------------------------------------------- class CTimer0Interrupt { public: CTimer0Interrupt(); ~CTimer0Interrupt(); private: // Overflow interrupt handler. void TIMER0_OVF_vect(void) __attribute__ ((signal, __INTR_ATTRS)); }; //------------------------------------------- class CTimer0 { friend class CTimer0Interrupt; public: CTimer0(); ~CTimer0(); int GetTimer0Flag(void); // true if overflow occurred private: void SetOverflowFlag(void); // called from int handler private: volatile bool mTimer0Flag; CTimer0Interrupt mTimer0Interrupt; }; And in the cpp class implementation file, the method is: //--------------------------------------------------------------- // Timer0 overflow interrupt handler. // CLASS_ISR(CTimer0Interrupt, TIMER0_OVF_vect) { TCNT0 = TIMER0_TIMEOUT; // restart the timeout Timer0.SetOverflowFlag(); // tell our friend } Inserting the mangled name by hand in the macro above produces the vector alias that allows gcc to link the external C vector name while the C++ code remains unaware of its existence outside the owning class: extern "C" void __vector_16 (void) __attribute__ ((signal,used, externally_visible)) ; void __vector_16 (void) __attribute__((alias("_ZN16CTimer0Interrupt11__vector_16Ev"))); void CTimer0Interrupt::__vector_16(void) { (*(volatile uint8_t *)((0x32) + 0x20)) = 100; Timer0.SetOverflowFlag(); } Ron Kreymborg