Boost logo

Boost :

From: Bill Seymour (bill-at-the-office_at_[hidden])
Date: 2004-06-07 07:00:01


Rob Stewart:
>
> From: John Nagle <nagle_at_[hidden]>
> > > From: "Reece Dunn" <msclrhd_at_[hidden]>
> >
> > >> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk