Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Using "usb_names.h" doesn't work if my project has c++ code.

  1. #1

    Using "usb_names.h" doesn't work if my project has c++ code.

    Hi All,

    Creating a new file "usb_desc.c":

    Code:
    #include <usb_names.h>
    
    #define MANUFACTURER_NAME {'A','B','C'}
    #define MANUFACTURER_NAME_LEN 3
    #define PRODUCT_NAME {'T','E','S','T'}
    #define PRODUCT_NAME_LEN 4
    #define SERIAL_NUM {'0','0','0','1'}
    #define SERIAL_NUM_LEN 4
    
    struct usb_string_descriptor_struct usb_string_manufacturer_name = {
    2 + MANUFACTURER_NAME_LEN * 2,
    3,
    MANUFACTURER_NAME
    };
    
    struct usb_string_descriptor_struct usb_string_product_name = {
    2 + PRODUCT_NAME_LEN * 2,
    3,
    PRODUCT_NAME
    };
    
    struct usb_string_descriptor_struct usb_string_serial_number = {
    2 + SERIAL_NUM_LEN *2,
    3,
    SERIAL_NUM
    };
    It works totally fine, but if I add cpp code, it won't compile and gives me the following error:

    Code:
    too many initializers for 'uint16_t [0] {aka short unsigned int [0]}'
    Any thoughts?
    Last edited by avgsuperhero; 09-15-2021 at 10:02 PM.

  2. #2
    I figured it out. The problem was that I was putting
    Code:
    #include "usb_desc.c"
    in my .ino file. When I removed the include, everything worked well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •