delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/16/01:32:57

Sender: nate AT cartsys DOT com
Message-ID: <378EC477.DA0C222D@cartsys.com>
Date: Thu, 15 Jul 1999 22:34:47 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.10 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Marker
References: <378E8DD5 DOT 68B571A AT vetec DOT com>
Reply-To: djgpp AT delorie DOT com

Andy Goth wrote:
> 
> Is there any way of inserting a marker into C code that is compiled but
> not run?  It would be really helpful if I could put comments (of a sort)
> right into the binary.

If you don't care exactly where in the binary it ends up, you could just
do

static char my_comment[] = "Hello, world";

The compiler may warn you about an unused static variable, though.

> I imagine that maybe I could do it with inline assembly that jumps over
> a text string, but would the optimizer throw that out?

If you want to have it in just the right place, then yes, you could do
that.  Using `volatile' will prevent the optimizer from moving or
removing it (in fact I think it might not even be necessary for asms
with no output).

asm volatile("jmp 0f; .string \"Hello, world\"; 0:");

-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019