Topic: Can ios::xalloc return 0 as a valid index?
Author: imy@wcl-rs.bham.ac.uk (Ian Young)
Date: 19 Dec 1994 09:45:04 GMT Raw View
This is a slight rephrasing of a post to comp.lang.c++, in a thread
"ostream derivation - advice please." -- I didn't get an answer
there, but it's a standards question, so I thought I'd have a go here.
In article <jss-0912940002330001@166.90.100.8>,
Jerry Schwarz <jss@declarative.com> wrote:
[with regard to using xalloc and iword for misuse-checking in paired
sets of manipulators]
>Two refinements:
[The second refinement was: be paranoid about iword initialization,
regardless of what the current working paper says]
>
>1) Use a function to access the index value. This avoids order of
> initialization problems if you use mystream's in constructors
> of global objects.
>
> class mystream {
> public:
> static int myFpind() ;
> ...
> }
>
> int mystream::myFpind() {
> static int ix;
> if ( !ix ) ix = ios::xalloc() ;
> return ix;
> }
It's clear that this technique requires ios::xalloc not to return 0 as
a valid index. If it did, mystream::myFpind could return 0 on its
first call and a different value on subsequent calls.
ios::xalloc in the iostream library I have (came with our '92 vintage
IBM xlC) returns 0 as the first index.
Is this incorrect according to the _current_ state of the working
paper? Or did Jerry slip up?
Cheers,
Ian.