Message-ID: <37916761.BFEE55@vetec.com> Date: Sun, 18 Jul 1999 00:34:25 -0500 From: Andy Goth X-Mailer: Mozilla 4.61 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: Marker References: <378E8DD5 DOT 68B571A AT vetec DOT com> <7mnnns$39l$1 AT news DOT luth DOT se> <37914616 DOT 11FEAA6C AT vetec DOT com> <37915EED DOT 5D68DAC AT cartsys DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com > > > : 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. > > > : > > > : I imagine that maybe I could do it with inline assembly that jumps over > > > : a text string, but would the optimizer throw that out? > > > > > > Hmm. Will the compiler remove 'const char s[] = "My string\n";'? > > > > > > If it does try 'struct { char s[], void *p } my_var = { "My string\n", > > > &my_var };' wihch I haven't tested but should work. The trick is to > > > make sure you reference the string somewhere in the code. > > > > What does the void* p part do (besides add four extra unused bytes)? > > The structure needs to be referenced. If it has a pointer in it, it can > reference itself. Neat trick, that. Yes, it's neat. New question!! I'm just checking here. The following compiles in DJGPP, but I am unsure whether or not it is standard. Here goes... Classes I use in this example: ReqDrawMsg, Message, Box, Point, and Screenport ReqDrawMsg's constructor takes (const Box&). ReqDrawMsg is derived from Message. Box's constructor takes (const Point&, const Point&). Point's constructor takes (int, int). Screenport has an operator<< that takes (const Message&). // #includes int main() { Screenport theScreen; theScreen << ReqDrawMsg(Box(Point(5, 5), Point(20, 20))); return 0; } The whole point of this is to avoid the clumsy alternative: int main() { Screenport theScreen; Point ul(5, 5); Point lr(20, 20); Box box(ul, lr); ReqDrawMsg draw(box); theScreen << draw; return 0; } Am I free to use the first version? Does it compile *correctly*? I can't test that yet since no functions have implementations. Will it compile correctly on other platforms and other (working) compilers? Are there any gotchas I should be aware of? ___ _ _ ____ _ _ / _ \| \ | | _ \\ \_/ / .--------[ ICQ#: 35256413 ]--------. | |_| | \| | | | |\ / | 01001000011001010110110001101100 | | _ | \ \ | | | | | | | 01101111001011000010000001110111 | | | | | |\ | |_| | | | | 01101111011100100110110001100100 | |_| |_|_| \_|____/ |_| `--[ mailto:andygoth AT vetec DOT com ]---'