This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: What is the address of this line?
- From: Brian Dessent <brian at dessent dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 19 Jun 2006 17:15:05 -0700
- Subject: Re: What is the address of this line?
- References: <Pine.LNX.4.64.0606191643550.13331@parore>
- Reply-to: gcc-help at gcc dot gnu dot org
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