From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27537 invoked by alias); 20 Jun 2006 00:15:09 -0000 Received: (qmail 27529 invoked by uid 22791); 20 Jun 2006 00:15:09 -0000 X-Spam-Check-By: sourceware.org Received: from dessent.net (HELO dessent.net) (69.60.119.225) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 20 Jun 2006 00:15:07 +0000 Received: from localhost ([127.0.0.1] helo=dessent.net) by dessent.net with esmtp (Exim 4.61) (envelope-from ) id 1FsTtZ-0007cY-Jr for gcc-help@gcc.gnu.org; Tue, 20 Jun 2006 00:15:05 +0000 Message-ID: <44973E09.ABEE8C32@dessent.net> Date: Tue, 20 Jun 2006 00:15:00 -0000 From: Brian Dessent Reply-To: gcc-help@gcc.gnu.org X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Re: What is the address of this line? References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2006-06/txt/msg00153.txt.bz2 John Carter wrote: > So we using gcc on an embedded platform. ie. Very constrained flash & ram. > > We also using asserts. > > Storing __LINE__ and __FILE__ is taking too much flash. > > Question: I would like to create an assert macro .... > > #define Assert( expression) do {\ > if(!(expression)) { \ > assert_occurred_at_program_counter = THE_ADDRESS_OF_THIS_LINE(); \ > } > } while(0) > > So how do I write that magical function / macro > THE_ADDRESS_OF_THIS_LINE(); That returns the address / PC at that line? > Preferable in a CPU neutral fashion, otherwise for a Sparc CPU. How about something like: (see also section 5.2 of the manual) #define Assert(expression) ({ \ __label__ here; \ if (!(expression)) { \ here: assert_occurred_at_program_counter = &&here; \ } \ }) Brian