Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > void * in ANSC

Reply
Thread Tools

void * in ANSC

 
 
Army1987
Guest
Posts: n/a
 
      02-04-2008
Keith Thompson wrote:

> In C99 6.5.3.2, the only constraint for the unary "*" operator is:
>
> The operand of the unary * operator shall have pointer type.
>
> and void* is a pointer type. Obviously there's very little you can do
> with the result, but this:
>
> void *ptr = /* some non-null value */
> *ptr;
>
> appears to be legal (though not particularly useful).


This has a curious consequence:
volatile void *ptr = SOMEWHERE;
*ptr;

How many bytes does that access?



--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
 
 
 
Peter Nilsson
Guest
Posts: n/a
 
      02-04-2008
Army1987 <(E-Mail Removed)> wrote:
> Keith Thompson wrote:
> > In C99 6.5.3.2, the only constraint for the unary "*"
> > operator is:
> >
> > * * The operand of the unary * operator shall have pointer
> > type. and void* is a pointer type. *Obviously there's very
> > little you can do with the result, but this:
> >
> > * * void *ptr = /* some non-null value */
> > * * *ptr;
> >
> > appears to be legal (though not particularly useful).

>
> This has a curious consequence:
> * * *volatile void *ptr = SOMEWHERE;
> * * **ptr;
>
> How many bytes does that access?


None. [How many bytes does any other void expression access?]

--
Peter
 
Reply With Quote
 
 
 
 
Army1987
Guest
Posts: n/a
 
      02-04-2008
Peter Nilsson wrote:

> Army1987 <(E-Mail Removed)> wrote:
>> * * *volatile void *ptr = SOMEWHERE;
>> * * **ptr;
>>
>> How many bytes does that access?

>
> None. [How many bytes does any other void expression access?]

(void)memcpy(foo, bar, 42) accesses 42 bytes.



--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      02-04-2008
Army1987 wrote:

> (void)memcpy(foo, bar, 42) accesses 42 bytes.

84 bytes, I meant.

--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      02-04-2008
Army1987 <(E-Mail Removed)> wrote:
> Peter Nilsson wrote:
> > Army1987 <(E-Mail Removed)> wrote:
> > > * * *volatile void *ptr = SOMEWHERE;
> > > * * **ptr;
> > >
> > > How many bytes does that access?

> >
> > None. [How many bytes does any other void expression
> > access?]

>
> (void)memcpy(foo, bar, 42) accesses [84] bytes.


How many bytes does the following access?

memcpy;

--
Peter
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      02-04-2008
In article <fo6th2$mls$(E-Mail Removed)>, Army1987 <(E-Mail Removed)> wrote:
>Army1987 wrote:


>> (void)memcpy(foo, bar, 42) accesses 42 bytes.


>84 bytes, I meant.


How do you arrive at that number? memcpy() does not define
the behaviour if the fields overlap. memmove() is the function
that defines the copying "as if" the data were copied into a
temporary buffer, and if such temporary copies were to take
place then Yes that would increase the byte count, but as you
have not defined the extent to which foo overlaps with bar,
you cannot say with any degree of certainty -exactly- how many
bytes would be accessed or how many times those bytes would be
accessed.
--
"Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson
 
Reply With Quote
 
Harald van Dijk
Guest
Posts: n/a
 
      02-04-2008
On Mon, 04 Feb 2008 14:08:56 -0800, Peter Nilsson wrote:
> How many bytes does the following access?
>
> memcpy;


None. You've got a function designator which is not the operand of sizeof
or &, so it automatically gets converted to a pointer to memcpy. Besides,
functions aren't objects, and don't have to be made up of bytes at all,
and in some cases really might not be -- consider a C program running on
a virtual machine, where memcpy is implemented as a system call to the
host.
 
Reply With Quote
 
Harald van Dijk
Guest
Posts: n/a
 
      02-04-2008
On Mon, 04 Feb 2008 22:21:04 +0000, Walter Roberson wrote:
> In article <fo6th2$mls$(E-Mail Removed)>, Army1987 <(E-Mail Removed)>
> wrote:
>>Army1987 wrote:

>
>>> (void)memcpy(foo, bar, 42) accesses 42 bytes.

>
>>84 bytes, I meant.

>
> How do you arrive at that number? memcpy() does not define the behaviour
> if the fields overlap.


So assuming the fields don't overlap, memcpy reads 42 bytes, and writes
42 different bytes, so accesses 84 bytes in total.
 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      02-04-2008
> Army1987 <(E-Mail Removed)> wrote:
> > Peter Nilsson wrote:
> > > Army1987 <(E-Mail Removed)> wrote:
> > > > * * *volatile void *ptr = SOMEWHERE;
> > > > * * **ptr;
> > > >
> > > > How many bytes does that access?
> > >
> > > None. [How many bytes does any other void expression
> > > access?]

> >
> > (void)memcpy(foo, bar, 42) accesses [84] bytes.

<snip>

[In light of Harald van Dijk's point on my followup...]
How many bytes does the following access?

memcpy(foo, bar, 0);

If it's none, then why should *memcpy(foo, bar, 0) be
any different? If it isn't different, then why should
dereferencing a volatile void pointer be any different?

--
Peter
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      02-04-2008
In article <1fad2$47a790c3$541dfcd3$(E-Mail Removed)1.nb.ho me.nl>,
=?UTF-8?q?Harald_van_D=C4=B3k?= <(E-Mail Removed)> wrote:
>On Mon, 04 Feb 2008 22:21:04 +0000, Walter Roberson wrote:
>> In article <fo6th2$mls$(E-Mail Removed)>, Army1987 <(E-Mail Removed)>
>> wrote:
>>>Army1987 wrote:


>>>> (void)memcpy(foo, bar, 42) accesses 42 bytes.


>>>84 bytes, I meant.


>> How do you arrive at that number? memcpy() does not define the behaviour
>> if the fields overlap.


>So assuming the fields don't overlap, memcpy reads 42 bytes, and writes
>42 different bytes, so accesses 84 bytes in total.


I must have been having a Duh moment.

Okay, so I'll turn it around: since the overlap of foo and bar is
not defined, we don't know that they occupy 42 distinct bytes each;
for example they might be offset by one byte from each other and
perhaps only 43 distinct bytes are accessed, 41 of them twice each.
The memcpy result is not defined for overlap, so we don't know
what the answer will be (fault for overlapping DMA perhaps), but
we can't say 84 bytes accessed for sure.

--
"Any sufficiently advanced bug is indistinguishable from a feature."
-- Rich Kulawiec
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between void proba(); and void proba(void); ??? PencoOdStip@gmail.com C++ 1 05-23-2007 07:12 PM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
returning a void (*)(void) Sergio C++ 6 01-05-2005 08:30 PM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM



Advertisments