Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > question

Reply
Thread Tools

question

 
 
chump1708@yahoo.com
Guest
Posts: n/a
 
      12-15-2005
can anyone tell me what does the following mean??

1.
void* abc()
{
}

is void a generic pointer??? and if yes what does it mean....


2.
also
what does the function

char ** abc()
{
}
return.....
i.e. does it return a 2d array of pointers????

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      12-15-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> can anyone tell me what does the following mean??
>
> 1.
> void* abc()
> {
> }

It means that function abc() returns a pointer of type void.

> is void a generic pointer??? and if yes what does it mean....

Yes.
Assuming you know the type of object it points to, you can use it
via a cast to access the object.

> 2.
> also
> what does the function
>
> char ** abc()
> {
> }
> return.....

It returns a pointer to a pointer of type char.

> i.e. does it return a 2d array of pointers????

It could, among other things...

 
Reply With Quote
 
 
 
 
chump1708@yahoo.com
Guest
Posts: n/a
 
      12-15-2005
well....regarding question 1, I guess we need not typecast it....
regarding question 2, It returns a pointer to a pointer of type char -
what do u exactly mean???


do you mean
that

ptr1 -> some location

ptr2-> address of ptr1

Is this what u mean??

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      12-15-2005
(E-Mail Removed) wrote:
> well....regarding question 1, I guess we need not typecast it....
> regarding question 2, It returns a pointer to a pointer of type char -
> what do u exactly mean???
>
>
> do you mean
> that
>
> ptr1 -> some location
>
> ptr2-> address of ptr1
>
> Is this what u mean??


A Note: please give attribution to your posts.

Firstly, you *must* typecast a void pointer or the compiler will report
an error.
Secondly, yes:
If ptr1 is a pointer of type char and if ptr2 is a pointer of type char
initialised
with the address of ptr1, then ptr2 is a pointer to a pointer of type
char.

 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      12-15-2005
santosh wrote:

> (E-Mail Removed) wrote:
>> can anyone tell me what does the following mean??
>>
>> 1.
>> void* abc()
>> {
>> }

> It means that function abc() returns a pointer of type void.
>
>> is void a generic pointer??? and if yes what does it mean....

> Yes.


No. /pointer to/ void is a generic pointer type.

> Assuming you know the type of object it points to, you can use it
> via a cast to access the object.


Or an assignment. You don't /need/ a cast, although it might
be the most appropriate thing to use.

--
Chris "Spice" Dollin
oxygen is a highly reactive waste-product of plant life.
 
Reply With Quote
 
Chuck F.
Guest
Posts: n/a
 
      12-15-2005
(E-Mail Removed) wrote:
> can anyone tell me what does the following mean??
>
> 1.
> void* abc()
> {
> }
>
> is void a generic pointer??? and if yes what does it mean....
>

No, but void* is a generic pointer. Any pointer can be cast
(explicitly or implicitly) to void* and back again.

>
> 2.
> also
> what does the function
>
> char ** abc()
> {
> }
> return.....
> i.e. does it return a 2d array of pointers????


No. It returns a pointer to a pointer to char.

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
 
Reply With Quote
 
Robert Gamble
Guest
Posts: n/a
 
      12-15-2005
santosh wrote:
> (E-Mail Removed) wrote:
> > can anyone tell me what does the following mean??
> >
> > 1.
> > void* abc()
> > {
> > }

> It means that function abc() returns a pointer of type void.


It is better said that abc returns a pointer to void.

> > is void a generic pointer??? and if yes what does it mean....

> Yes.
> Assuming you know the type of object it points to, you can use it
> via a cast to access the object.


A *pointer to void* is a generic object pointer in at least one sense
of the word, *void* is something completely different.

> > 2.
> > also
> > what does the function
> >
> > char ** abc()
> > {
> > }
> > return.....

> It returns a pointer to a pointer of type char.
>
> > i.e. does it return a 2d array of pointers????

> It could, among other things...


Well, not, it couldn't. You don't return arrays at all in C. This
function will return a pointer to pointer to char every time. The
pointer it returns could be used to access an array but it isn't the
array that is being returned.

Robert Gamble

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      12-15-2005
Robert Gamble wrote:
> santosh wrote:
> > (E-Mail Removed) wrote:

<snip>
> > > i.e. does it return a 2d array of pointers????

> > It could, among other things...

>
> Well, not, it couldn't. You don't return arrays at all in C. This
> function will return a pointer to pointer to char every time. The
> pointer it returns could be used to access an array but it isn't the
> array that is being returned.


You're right. I meant to mean the same thing, but looking back, i can
see, it's both misleading and ridiculous.

I'll check my wording carefully before posting further.
thanks

 
Reply With Quote
 
Alok Singhal
Guest
Posts: n/a
 
      12-15-2005
On Thu, 15 Dec 2005 06:06:17 -0800, santosh wrote:
> Firstly, you *must* typecast a void pointer or the compiler will report
> an error.


No, one does not need to cast a void pointer to assign it to
another pointer, or the other way around:

6.5.16.1 Simple assignment
Constraints
One of the following shall hold:

one operand is a pointer to an object or incomplete type and the other
is a pointer to a qualified or unqualified version of void, and the type
pointed to by the left has all the qualifiers of the type pointed to by
the right;

Also look at the example in section 6.5.3.4 (The sizeof operator) in the
standard:

extern void *alloc(size_t);
double *dp = alloc(sizeof *dp);

The above should be an error according to you.

This is legal:

void *vp;
double d, *dp;
vp = &d;
dp = vp;

-Alok
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      12-15-2005
santosh wrote:

> Firstly, you *must* typecast a void pointer
> or the compiler will report an error.


If your compiler gives an error
from not casting the return value of malloc,
that means that you neglected to #include <stdlib.h>.

http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html

Errata for The C Programming Language, Second Edition

142(6.5, toward the end):
The remark about casting the return value of malloc
("the proper method is to declare ... then explicitly coerce")
needs to be rewritten. The example is correct and works,
but the advice is debatable in the context of the
1988-1989 ANSI/ISO standards. It's not necessary
(given that coercion of void * to ALMOSTANYTYPE * is automatic),
and possibly harmful if malloc, or a proxy for it,
fails to be declared as returning void *.
The explicit cast can cover up an unintended error.
On the other hand, pre-ANSI, the cast was necessary,
and it is in C++ also.

--
pete
 
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
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments