0

I recently came upon this snippet:

extern const uint8_t server_root_cert_pem_start[] asm("_binary_server_root_cert_pem_start");
//                                                ^^^^^^^^^^^^^ what's going on here?

in the esp-idf examples(line 74). I cannot understand the declaration, and my online search hasn't been successful. My best guess would be that this code:

  • Uses uint8_t as a replacement for char since they have the same size (1 byte). No clue why though

  • Ultimately declares a string (a const char array) by inferring the array size from the string length whose length has been specified outside our module

Even if my assumptions are correct, I fail to understand why it's written this way or what happens with "null termination" in this case. So the actual questions:

  • What is this code doing?
  • Why is it doing it this way (advantages)?
  • Are there any implications that differentiate it from a simple C-style declaration?
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Lorah Attkins
  • 5,331
  • 3
  • 29
  • 63

1 Answers1

1

This is compiler dependend. However my guess is that this code declare an array named server_root_cert_pem_start and binds it to another symbol (memory location) _binary_server_root_cert_pem_start probably defined elsewhere (in an assembly file?)

Damiano
  • 698
  • 7
  • 19
  • Yes, this is GNU C syntax to set the asm symbol name for a variable, e.g. to hard-code the leading `_`. https://gcc.gnu.org/onlinedocs/gcc/Asm-Labels.html – Peter Cordes Nov 13 '19 at 15:25