Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-06-04 15:00:07


From: John Nagle <nagle_at_[hidden]>
> > From: "Reece Dunn" <msclrhd_at_[hidden]>
>
> >>I am looking for a better solution to this. I am also thinking about how to
> >>remove the ABC from the implementation using a technique pointed out by
> >>someone on this thread (can't remember who):
> >>
> >> 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? That will
> work with most implementations, but it's not guaranteed
> to work. There are often intervening alignment bytes.
> Some debug implementations may place sentinel
> areas between objects to detect buffer overruns.

Oh, right. It was C99 that blessed the struct hack. Oh well.

Maybe we could do it anyway on platforms where it's been proven
to work?

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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