avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] PSTR() in static initialisers


From: Paul \"LeoNerd\" Evans
Subject: [avr-libc-dev] PSTR() in static initialisers
Date: Wed, 31 Jan 2018 20:01:25 +0000

I want to write

  static struct MenuLevel {
    uint8_t (*get)(void);
    void (*set)(uint8_t);
    uint8_t max;
    const char *name;
  } menu[] = {
    { .get = &get_mode,  .set = &set_mode,  .max = MODE_MAX,
      .name = PSTR("MODE"), },
    { .get = &get_sense, .set = &set_sense, .max = 1,
      .name = PSTR("SENSE"), },
    { .get = &get_range, .set = &set_range, .max = 1,
      .name = PSTR("RANGE"), },
  };

but I can't, because it fails to compile:

  In file included from src/ui.c:5:0:
  src/ui.c:263:13: error: braced-group within expression allowed only inside a 
function
       .name = PSTR("MODE"), },

This is due to the definition of PSTR which looks like

  # define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); 
&__c[0];}))

Does anyone have a suggestion on how I can have a string pointer to a
flash-stored string in a static initialiser?

-- 
Paul "LeoNerd" Evans

address@hidden      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

Attachment: pgpJjcv81Luq8.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]