Hi, I'm using TBuffers so I can use Root streamers for writing to non-filesystem places (in my case an oracle database, but that doesn't really matter) and in the course of working with some char * variables came upon this: inline TBuffer &TBuffer::operator>>(Char_t *c) { ReadString(c, sizeof(c)); return *this; } inline TBuffer &TBuffer::operator<<(const Char_t *c) { WriteString(c); return *this; } where ReadString takes a maximum number of bytes parameter and WriteString writes up to the terminating 0 in the string passed. With this code, using operator>> on a Char_t * variable will not read in the reverse of one that was written with an operator<<, since the sizeof(c) call will always resolve to 4 or maybe 8 on some machines. I think the best way to deal with that is for the operator>> to be cavalier about it and just overwrite memory, since it has no way of knowing how big the buffer it should write into is, and since the user programmer is working with char *'s, it's his responsibility to make sure the memory allocation and stuff is correct. If it breaks, one just shrugs and says, "you should've used TString..."; but I think it's unfair for the user to be bitten by operator>> not reading in, in exactly the same way, what operator<< wrote out. George Heintzelman gah@bnl.gov
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:40 MET