autc04 / Retro68

a gcc-based cross-compiler for classic 68K and PPC Macintoshes
GNU General Public License v3.0
548 stars 54 forks source link

Cannot initialise structures with Pascal string constants #251

Open mcayland opened 4 months ago

mcayland commented 4 months ago

Whilst trying to compile the QEMU VGA driver I came across an error when trying to initialise a structure with a Pascal string constant which can be demonstrated as below:

#include <VideoServices.h>
#include <DriverServices.h>

DriverDescription TheDriverDescription = {
        /*
         * Signature info
         */
        kTheDescriptionSignature,               /* OSType driverDescSignature */
        kInitialDriverDescriptor,               /* DriverDescVersion driverDescVersion */
        "\p.Display_Video_QemuVGA",
        0x01, 0x01,
        0, 0,
        /*
         * DriverOSRuntime driverOSRuntimeInfo
         */
        0                                       /* RuntimeOptions driverRuntime */
        | (0 * kDriverIsLoadedUponDiscovery)    /* Loader runtime options */
        | (1 * kDriverIsOpenedUponLoad)         /* Opened when loaded */
        | (1 * kDriverIsUnderExpertControl)     /* I/O expert handles loads/opens */
        | (0 * kDriverIsConcurrent)             /* concurrent */
        | (0 * kDriverQueuesIOPB),              /* Internally queued */
        "\p.Display_Video_QemuVGA",             /* Str31 driverName (OpenDriver param) */
        0, 0, 0, 0, 0, 0, 0, 0,                 /* UInt32 driverDescReserved[8] */
        /*
         * DriverOSService Information. This section contains a vector count followed by
         * a vector of structures, each defining a driver service.
         */
        1,                                      /* ServiceCount nServices */
        /*
         * DriverServiceInfo service[0]
         */
        kServiceCategoryNdrvDriver,             /* OSType serviceCategory */
        kNdrvTypeIsVideo,                               /* OSType serviceType */
        1, 0, 0, 0
};

When compiled with powerpc-apple-macos-gcc test.c the following error is emitted:

test.c:10:9: error: cannot initialize array of 'unsigned char' from a string literal with type array of 'unsigned char'
   10 |         "\p.Display_Video_QemuVGA",
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:10:9: note: (near initialization for 'TheDriverDescription.driverType.nameInfoStr')
test.c:22:9: error: cannot initialize array of 'unsigned char' from a string literal with type array of 'unsigned char'
   22 |         "\p.Display_Video_QemuVGA",             /* Str31 driverName (OpenDriver param) */
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:22:9: note: (near initialization for 'TheDriverDescription.driverOSRuntimeInfo.driverName')

If I change the constants from e.g. "\p.Display_Video_QemuVGA" to "\n.Display_Video_QemuVGA" then compilation succeeds so it seems to be related to the implementation of Pascal string constants.