💾 SuperFloppies Place! 💾

Variable Length Array in C, #2

This example compiles using gcc 8.2.0 using the C99 language implementation.

Command line used: gcc -std=gnu99 -o vla vla.c

Based on example by @gudenau@mastodon.technology

Code

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <wchar.h>

#define USB_DESCRIPTOR_STRING 0
#define STRING_MANUFACTURER L"gudenau"
#define PROGMEM

typedef struct {
 uint8_t type;
 uint8_t size;
 wchar_t string[];
} USBDescriptorString;

static const USBDescriptorString PROGMEM manufacture = {
 USB_DESCRIPTOR_STRING,
 sizeof(STRING_MANUFACTURER),
 STRING_MANUFACTURER
};

int
main(int argc, char *argv[]) {
        printf("%u\n", sizeof(manufacture));
        return 0;
}

The sizeof is incorrect, though, returning 4 on my system.