basic quantum of (void *) 
Author Message
 basic quantum of (void *)

Does the ANSI-standard elaborate on the basic quantum when
incrementing a (void *) ? Is the increment sizeof(char) or
the size of 1 byte (8 bit) when doing something like:

void *tmp;
..
++tmp;

?

Any help and pointers are highly appreciated.
Thanks in advance.

Malte.
--
Malte Lance.
--- composed with knews
--



Sat, 20 Apr 2002 03:00:00 GMT  
 basic quantum of (void *)

Quote:

> Does the ANSI-standard elaborate on the basic quantum when
> incrementing a (void *) ? Is the increment sizeof(char) or
> the size of 1 byte (8 bit) when doing something like:

It isn't anything.  Pointer arithmetic on pointers to void is illegal.


 Alcyone Systems | irc maxxon (efnet) | web http://www.alcyone.com/max/
    San Jose, CA | languages en, eo | icbm 37 20 07 N 121 53 38 W
             USA | 425 days and counting | &tSftDotIotE
 __
/  \ No man who needs a monument ever ought to have one.
\__/ Nathaniel Hawthorne
--



Sun, 21 Apr 2002 03:00:00 GMT  
 basic quantum of (void *)

Quote:

> Does the ANSI-standard elaborate on the basic quantum when
> incrementing a (void *) ? Is the increment sizeof(char) or
> the size of 1 byte (8 bit) when doing something like:

> void *tmp;
> ..
> ++tmp;

Pointer arithmetic on type void* is illegal.  This makes sense;
pointer arithmetic is defined in terms of the type the pointer points
to, and void* doesn't point to anything.

The gcc compiler supports arithmetic on void* as an extension
(treating it like char*).  (I guess this avoids the inconvenience of
finding certain errors too soon.  8-)}) If you use "-pedantic", it
will issue a warning.

--

San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
"Oh my gosh!  You are SO ahead of your time!" -- anon.
--



Sun, 21 Apr 2002 03:00:00 GMT  
 basic quantum of (void *)

Quote:

> Does the ANSI-standard elaborate on the basic quantum when
> incrementing a (void *) ?

Yeah -- you can't do that (in a strictly conforming program).
--



Sun, 21 Apr 2002 03:00:00 GMT  
 basic quantum of (void *)

Quote:

>Does the ANSI-standard elaborate on the basic quantum when
>incrementing a (void *) ?

A void pointer isn't a complete type, so you can't manipulate it
this way.

Quote:
>Is the increment sizeof(char) or
>the size of 1 byte (8 bit) when doing something like:

A void pointer has the same representation and alignment as a char
pointer. This is because it has to be able to point to anything and
memory can be looked at as an array of chars. But you still need to
complete its type before you use it. Defaulting to a char pointer
is an extension and is not part of ANSI C.

--
Craig

Manchester, NH
"Astrology is not particularly good at handling numbers over 30."
-- Eminent British Astrologer when asked about predicting the lottery.
--



Sun, 21 Apr 2002 03:00:00 GMT  
 basic quantum of (void *)
Many thanks to all who replied and gave suggestion to my problem.
Still, my problem is not solved so far.
The background-info:
  1. There is a black-box
  2. The black box gets an inputstream of data, where the type
     of the data is not known at compiletime.
  3. The black box should convert the inputstream of data wrt the
     type and output a stream of data, where the type of the
     outputdata is not known at compiletime.

I've written a pool of small functions that do elementary
type-casting. Every one of this functions has two arguments:
 - src
 - dst
and "src" is assigned to "dst" with the appropriate type-cast.
At runtime the programm determines the alignment and size of the
input/output data and does set a generic function-pointer to the
appropriate conversion-function. Then the stream of data is
converted by just calling the function the generic functionpointer
is pointing at.
For some bizarre reason, the conversion-function should not
be able to increment the pointer that are pointing at the datastreams.
This has to be done outside of the "small" conversion function.
The qsort example in K&R p.115 (german version) came to mind and
since the example is using (void *) for good reason, and the example
exactly matched my needs, i had to know what the size of the basic
quantum of a (void *) is, just to be able to increment my pointers
correct outside of the "small" conversion function. If it happens to
be sizeof(char), i am curious if sizeof(char) is 8 bit on all
existing OS.

So far the background story.
Hopefully someone could enlighten me on the topic of (void *)
and/or suggest an appropriate strategy to do what i tried to
describe above.

Thanks again for all your help in advance.

Malte.



Quote:
> Does the ANSI-standard elaborate on the basic quantum when
> incrementing a (void *) ? Is the increment sizeof(char) or
> the size of 1 byte (8 bit) when doing something like:

> void *tmp;
> ..
> ++tmp;

> ?

> Any help and pointers are highly appreciated.
> Thanks in advance.

> Malte.

--
Malte Lance.
--- composed with knews
--



Mon, 22 Apr 2002 03:00:00 GMT  
 basic quantum of (void *)

Quote:

> ..., i had to know what the size of the basic
> quantum of a (void *) is, just to be able to increment my pointers
> correct outside of the "small" conversion function. If it happens to
> be sizeof(char), i am curious if sizeof(char) is 8 bit on all
> existing OS.

We already explained that there is no "quantum" for (void*).
sizeof(char)==1 on all conforming C implementations.
CHAR_BIT is at least 8 but may be larger, 9 and 16 being two
of the most common alternatives.

If you have by some other means determined the size of an
object in an array of objects pointed to by the (void*),
then there is a simple way to increment the pointer:
        void *p;        // the pointer to be incremented
        size_t s;       // the object size in bytes
        ...
        p = (void*)((char*)p + s);
--



Thu, 25 Apr 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. basic quantum of (void *)

2. from void (void*) to void (_cdecl*) (void*)

3. what's the difference between void main(void) and int main(void)

4. difference between void foo(void) and void foo()

5. ftime quantum behaviour

6. E-Quantum is waiting for you

7. quantum mechanics

8. typedef int COMPARE(const void *, const void *);

9. difference between void and <bold>void

10. void * & void

11. typedef void PF(int, void *);

12. Purpose of void main (void) and Functions

 

 
Powered by phpBB® Forum Software