[Gllug] Pointer arithmetic with void *

Nix nix at esperi.demon.co.uk
Sun Aug 18 18:54:04 UTC 2002


On Thu, 15 Aug 2002, Tethys moaned:
> 
>>I know this is a Linux list and not alt.lang.cpp or similar, but have you 
>>considered using C++ and iostreams? Perfect for this sort of thing.
>>
>> [...]
>>
>>  // then you can grab whitespaced tokens like this:
>>  string token;
>>  ss >> token;
>>  
>>  // or get individual chars like this:
>>  char c;
>>  ss.get(c)
>>
>>  // or indeed whole chunks:
>>  char chunk[size];
>>  ss.get(chunk, size);
> 
> ...and for grabbing a variable length integer where the length is
> determined by magic bits in the first and subsequent bytes read?

You define a type that represents such an integer, and define
an operator>> for that type. Then you can forget about it.

>                                              what does the above
> give you over just reading the appropriate amount of data directly
> from the mmap()ed region in C (either via a direct cast to a suitable
> data type, or via a memcpy)?

The above, nothing, but it's very bad style --- it uses *arrays*, for
goodness' sake. This is the sort of thing the list<> or perhaps deque<>
is for :)

-- 
`Mips are real and bitrate earnest, shifting spam is not our goal;
 silicon to sand returnest, was not spoken of the soul.'
   --- _Eventful History: Version 1.x_, John M. Ford

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list