Re: [cc65] Repeated string in struct array

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2011-07-10 02:07:45
On Fri, Jul 08, 2011 at 10:41:49AM -0700, Joseph Rose wrote:
>    Let's say I am defining an array of a struct type.  The struct has a char*
>    field.  The field in subscript 3 is the same as the one in subscript 2.  I
>    want to shorten #3 to an offset to #2's data.  How do I do that?

I don't know exactly what you mean. When using string literals, the compiler
will usually merge even partial strings. So in the example

        struct {
            const char* s;
        } bar[] = {
            { "hello world" },
            { "world" },
        };
        
there is only one string "hello world" and the second char pointer points into
the same storage.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Jul 10 02:07:52 2011

This archive was generated by hypermail 2.1.8 : 2011-07-10 02:07:55 CEST