Specifically, I was wondering if I could make something like this:
typedef struct {
char *s; /* still a cstr, with '0' bit at end */
size_t len;
} str;
str *newstr(char *s) {/*...*/};
void freestr(str *s) {/*...*/};
and do things like this (treat it as a cstr with stdlib/string functions):
int main() {
str *s = newstr("hello");
printf("The first character of '%s' is '%c'", *s, (*s)[0]);
freestr(s);
}
If not, it’s not a big deal—and, of course, I’m not really concerned about wasting a byte.
No, that’s a place where the standard explicitly forbids placing any padding. The address of the first member of a struct and the address of the struct must be the same.
Section 6.7.2.1 (15) in the n1570 draft of the C2011 standard states:
(emphasis mine)