Jump to page: 1 2 3
Thread overview
void no type
Mar 04, 2004
Phill
Mar 04, 2004
Matthias Becker
Mar 04, 2004
C
Mar 05, 2004
Phill
Mar 04, 2004
Vathix
Mar 04, 2004
C
Mar 04, 2004
Vathix
Mar 05, 2004
Phill
Mar 05, 2004
Phill
Mar 05, 2004
Vathix
Mar 05, 2004
Phill
Mar 05, 2004
Phill
Mar 06, 2004
Ilya Minkov
Mar 06, 2004
Phill
Mar 06, 2004
Ilya Minkov
Mar 06, 2004
Phill
Mar 06, 2004
Ilya Minkov
Mar 06, 2004
Phill
Mar 05, 2004
Walter
Mar 06, 2004
Phill
Mar 06, 2004
J Anderson
March 04, 2004
Ive got a (probably)dumb question here.

What is a void? I thought it was nothing.
It seems that in D it has a new meaning.

For example, how do I call this method?

aMethod(void[] buf)
{
}

It seems to me that I should need a char[]

I had a quick look at  the digtalsmars/d
but couldnt see it, and URL's or quick
tutorials via here, would be great :o))

Thanks for any help.

Phill.



March 04, 2004
>Ive got a (probably)dumb question here.
>
>What is a void? I thought it was nothing.
>It seems that in D it has a new meaning.
>
>For example, how do I call this method?
>
>aMethod(void[] buf)
>{
>}

Interesting. In C a pointer to void was used for some kind of generic
programming. E.g. malloc/free (C's way to dynamically (de)allocate memory) used
this:

void * malloc (size_t);
void free (void * ptr);


Type * memory = (Type *)malloc(size);
..
free (memory);


But I don't know what void-arrays could be used for in D.


March 04, 2004
Where do you see this method ?  You cant have an array of void , but usually 'void *' just means ( a chunk of data, no specified type ).  It's useful for manipulating raw data, coming in from sockets for example.  Marking a function as returning void means return nothing ( it is confusing now that u mention it, its just been around so long nobody thinks about it :) )

C

On Thu, 4 Mar 2004 20:22:17 +1100, Phill <phill@pacific.net.au> wrote:

> Ive got a (probably)dumb question here.
>
> What is a void? I thought it was nothing.
> It seems that in D it has a new meaning.
>
> For example, how do I call this method?
>
> aMethod(void[] buf)
> {
> }
>
> It seems to me that I should need a char[]
>
> I had a quick look at  the digtalsmars/d
> but couldnt see it, and URL's or quick
> tutorials via here, would be great :o))
>
> Thanks for any help.
>
> Phill.
>
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
March 04, 2004
Phill wrote:

> Ive got a (probably)dumb question here.
> 
> What is a void? I thought it was nothing.
> It seems that in D it has a new meaning.
> 
> For example, how do I call this method?
> 
> aMethod(void[] buf)
> {
> }
> 
> It seems to me that I should need a char[]
> 
> I had a quick look at  the digtalsmars/d
> but couldnt see it, and URL's or quick
> tutorials via here, would be great :o))
> 
> Thanks for any help.
> 
> Phill.
> 

It's actually a nice feature that allows you to have an array of any type, for example:

int[1] test;
void[] v = test;
printf("v.length = %d", v.length);

Prints out 4, without needing to cast or do length * size math. I used void[] in the send and receive methods of my Socket class.

-- 
Christopher E. Miller
March 04, 2004
Hmm, I didnt know you could have an array of void.  I distinctly remember the compielr telling me I couldn't.  My mistake :S.

C

On Thu, 04 Mar 2004 17:59:05 -0500, Vathix <vathix@dprogramming.com> wrote:

> Phill wrote:
>
>> Ive got a (probably)dumb question here.
>>
>> What is a void? I thought it was nothing.
>> It seems that in D it has a new meaning.
>>
>> For example, how do I call this method?
>>
>> aMethod(void[] buf)
>> {
>> }
>>
>> It seems to me that I should need a char[]
>>
>> I had a quick look at  the digtalsmars/d
>> but couldnt see it, and URL's or quick
>> tutorials via here, would be great :o))
>>
>> Thanks for any help.
>>
>> Phill.
>>
>
> It's actually a nice feature that allows you to have an array of any type, for example:
>
> int[1] test;
> void[] v = test;
> printf("v.length = %d", v.length);
>
> Prints out 4, without needing to cast or do length * size math. I used void[] in the send and receive methods of my Socket class.
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
March 04, 2004
C wrote:

> Hmm, I didnt know you could have an array of void.  I distinctly remember the compielr telling me I couldn't.  My mistake :S.
> 
> C
> 

It's not like a regular array though; since it has no defined type, you can't index or slice it. Maybe that was the error you got.

-- 
Christopher E. Miller
March 05, 2004
"Vathix" <vathix@dprogramming.com> wrote in message news:c28cbo$1oom$1@digitaldaemon.com...
> Phill wrote:
>
> > Ive got a (probably)dumb question here.
> >
> > What is a void? I thought it was nothing.
> > It seems that in D it has a new meaning.
> >
> > For example, how do I call this method?
> >
> > aMethod(void[] buf)
> > {
> > }
> >
> > It seems to me that I should need a char[]
> >
> > I had a quick look at  the digtalsmars/d
> > but couldnt see it, and URL's or quick
> > tutorials via here, would be great :o))
> >
> > Thanks for any help.
> >
> > Phill.
> >
>
> It's actually a nice feature that allows you to have an array of any type, for example:
>
> int[1] test;
> void[] v = test;
> printf("v.length = %d", v.length);
>
> Prints out 4, without needing to cast or do length * size math. I used void[] in the send and receive methods of my Socket class.

Yes thanks, very much, that is exactly where I
have seen it.
So I take it I can use a char[] instead of your int
example?

Thanks Phill.


> --
> Christopher E. Miller


March 05, 2004
yep Im aware of void (nothing) :o))
Its just an array of nothing that had me confused

Phill.


"C" <dont@respond.com> wrote in message news:opr4crhxpfehmtou@localhost... Where do you see this method ?  You cant have an array of void , but usually 'void *' just means ( a chunk of data, no specified type ).  It's useful for manipulating raw data, coming in from sockets for example. Marking a function as returning void means return nothing ( it is confusing now that u mention it, its just been around so long nobody thinks about it :) )

C

On Thu, 4 Mar 2004 20:22:17 +1100, Phill <phill@pacific.net.au> wrote:

> Ive got a (probably)dumb question here.
>
> What is a void? I thought it was nothing.
> It seems that in D it has a new meaning.
>
> For example, how do I call this method?
>
> aMethod(void[] buf)
> {
> }
>
> It seems to me that I should need a char[]
>
> I had a quick look at  the digtalsmars/d
> but couldnt see it, and URL's or quick
> tutorials via here, would be great :o))
>
> Thanks for any help.
>
> Phill.
>
>
>



--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


March 05, 2004
"Vathix" <vathix@dprogramming.com> wrote in message news:c28cbo$1oom$1@digitaldaemon.com...
> Phill wrote:
>
> > Ive got a (probably)dumb question here.
> >
> > What is a void? I thought it was nothing.
> > It seems that in D it has a new meaning.
> >
> > For example, how do I call this method?
> >
> > aMethod(void[] buf)
> > {
> > }
> >
> > It seems to me that I should need a char[]
> >
> > I had a quick look at  the digtalsmars/d
> > but couldnt see it, and URL's or quick
> > tutorials via here, would be great :o))
> >
> > Thanks for any help.
> >
> > Phill.
> >
>
> It's actually a nice feature that allows you to have an array of any type, for example:
>
> int[1] test;
> void[] v = test;
> printf("v.length = %d", v.length);
>
snip

From that code :

test.length  would equal 1 and
v.length would equal 4;

Do  you agree that this is inconsistent?
Is there a reason for this, or is it a bug(which I doubt)?

Phill.

> --
> Christopher E. Miller


March 05, 2004
Phill wrote:

> "Vathix" <vathix@dprogramming.com> wrote in message
> news:c28cbo$1oom$1@digitaldaemon.com...
>
>> Phill wrote:
>>
>>
>>> Ive got a (probably)dumb question here.
>>>
>>> What is a void? I thought it was nothing.
>>> It seems that in D it has a new meaning.
>>>
>>> For example, how do I call this method?
>>>
>>> aMethod(void[] buf)
>>> {
>>> }
>>>
>>> It seems to me that I should need a char[]
>>>
>>> I had a quick look at  the digtalsmars/d
>>> but couldnt see it, and URL's or quick
>>> tutorials via here, would be great :o))
>>>
>>> Thanks for any help.
>>>
>>> Phill.
>>>
>>
>> It's actually a nice feature that allows you to have an array of any
>> type, for example:
>>
>> int[1] test;
>> void[] v = test;
>> printf("v.length = %d", v.length);
>>
>
> snip
>
> From that code :
>
> test.length  would equal 1 and
> v.length would equal 4;
>
> Do  you agree that this is inconsistent?
> Is there a reason for this, or is it a bug(which I doubt)?
>
> Phill.


Not really inconsistent. This gives the same output, just requires the cast:

int[1] test;
byte[] v = cast(byte[])test;
printf("v.length = %d", v.length);

-- 
Christopher E. Miller
« First   ‹ Prev
1 2 3