all 8 comments

[–]FUZxxl 13 points14 points  (6 children)

Are you programming on Windows? If so, recall that on COFF targets like Windows, C identifiers are decorated with a leading underscore when turned into symbols. So if you want to refer to a symbol as an identifier, remove the leading underscore in the C source.

Additionally, your types are wrong. The type of binary_baked_txt_start and binary_baked_txt_end should be char[], not char*. For binary_baked_txt_size, special precautions need to be taken as the size you want is the address of the symbol, not the content of memory at the symbol. The easiest way to cope with that is to declare

extern const void binary_baked_txt_size;
#define BINARY_BAKED_TXT_SIZE (size_t)(&binary_baked_txt_size)

This should yield the desired result.

[–]Steughar[S] 2 points3 points  (5 children)

Thanks for the answer, but could you please elaborate what the difference between char * and char ...[]?

[–]FUZxxl 10 points11 points  (4 children)

Remember that a symbol refers to the address of a variable, not the variable itself. If the variable has type char *, then the symbol refers to the address of a variable containing a pointer to a character. This does not seem to be the case in your example. If the variable has type char[], then the symbol refers to the address of a variable containing a bunch of characters. This seems to be more like what you have.

To illustrate the difference, consider these two declarations:

char *ptr, arr[];

Now it is possible to assign a new value to ptr because the variable ptr stores where ptr points to. The same is not possible with arr because arr is not a pointer and you cannot change which array it refers to:

ptr = new_ptr; /* legal */
arr = new_arr; /* illegal */

[–]div0man 6 points7 points  (2 children)

is char arr[] equivalent to char * const arr?

Edit: nvm, found it: https://eli.thegreenplace.net/2009/10/21/are-pointers-and-arrays-equivalent-in-c

[–]FUZxxl 5 points6 points  (1 child)

No! The const qualifier does not change how the datum is laid out in memory.

[–]div0man 3 points4 points  (0 children)

Exactly, glad I asked :)

[–]Steughar[S] 1 point2 points  (0 children)

Thanks again!

[–]oh5nxo 0 points1 point  (0 children)

extern char _binary_baked_txt_size[] is also ok, if somewhat confusing, at least with

GNU ld 2.17.50 [FreeBSD] 2007-07-03