
Rob Stewart:
From: John Nagle <nagle@animats.com>
From: "Reece Dunn" <msclrhd@hotmail.com>
class fs_base { size_t len; szie_t capacity; // needed for buffer-safe operations CharT str[ 1 ]; // string manipulation functions
fs_base( size_t c ): capacity( c ){} };
template< size_t n > class fixed_string: public fs_base { CharT data[ n ]; fixed_string(): fs_base( n ){} };
Are you assuming that "data[n]" physically follows "str[1]" in memory, and that "data[n]" can be addressed by subscripting "str[1]" out of range? ...
Oh, right. It was C99 that blessed the struct hack. Oh well.
Well, yes; but the struct hack is not what the code above tries to do. What C99 says is that you can malloc sizeof(fs_base) plus some extra, then address str[2] to str[whatever up to malloc'd size]. Even in C99 (and even if C understood the C++-specific stuff in the above), there is no relationship between fs_base::str and fixed_string::data (except that they don't overlap). --Bill Seymour