Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Void variables (http://www.velocityreviews.com/forums/t946426-void-variables.html)

Raj Pashwar 05-21-2012 09:53 PM

Void variables
 
Hello

I would like to define a variable of void type. However I get compiler
errors:

void x; // error: variable or field ‘x’ declared void

Infact there is a typedef and I want to allow the defined type to be,
void. However, the error is the same.

Thankyou

John Gordon 05-21-2012 10:05 PM

Re: Void variables
 
In <jpedgm$br1$1@speranza.aioe.org> Raj Pashwar <raj121190@hotmail.NOSPAM.com> writes:

> Hello


> I would like to define a variable of void type. However I get compiler
> errors:


> void x; // error: variable or field ‘x’ declared void


> Infact there is a typedef and I want to allow the defined type to be,
> void. However, the error is the same.


I believe you are only allowed to declare void pointers, not plain voids.

This is allowable:

void *x;

But not this:

void x;

--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"


Ike Naar 05-21-2012 10:07 PM

Re: Void variables
 
On 2012-05-21, Raj Pashwar <raj121190@hotmail.NOSPAM.com> wrote:
> I would like to define a variable of void type.


How would such a variable be useful?

Ian Collins 05-21-2012 10:09 PM

Re: Void variables
 
On 05/22/12 09:53 AM, Raj Pashwar wrote:
> Hello
>
> I would like to define a variable of void type. However I get compiler
> errors:
>
> void x; // error: variable or field ‘x’ declared void
>
> Infact there is a typedef and I want to allow the defined type to be,
> void. However, the error is the same.


void is an incomplete type. You can't do anything with one, so why
would you want one?

--
Ian Collins

Joe Pfeiffer 05-21-2012 10:17 PM

Re: Void variables
 
Raj Pashwar <raj121190@hotmail.NOSPAM.com> writes:

> Hello
>
> I would like to define a variable of void type. However I get compiler
> errors:
>
> void x; // error: variable or field ‘x’ declared void
>
> Infact there is a typedef and I want to allow the defined type to be,
> void. However, the error is the same.
>
> Thankyou


As others have pointed out, you can't do this. This is one of those
questions that leads me to believe that there's something else you're
actually trying to do, and declaring a variable of type void seems like
a way to achive that underlying goal. So... what are you really trying
to do?

Kenny McCormack 05-21-2012 10:22 PM

Re: Void variables
 
In article <a1vspkFds4U7@mid.individual.net>,
Ian Collins <ian-news@hotmail.com> wrote:
>On 05/22/12 09:53 AM, Raj Pashwar wrote:
>> Hello
>>
>> I would like to define a variable of void type. However I get compiler
>> errors:
>>
>> void x; // error: variable or field ‘x’ declared void
>>
>> Infact there is a typedef and I want to allow the defined type to be,
>> void. However, the error is the same.

>
>void is an incomplete type. You can't do anything with one, so why
>would you want one?


I wonder if the goal was to get access to what in some languages (*) is
referred to as "WORD" - that is, something that isn't really an int or an
unsigned or anything else - but is just a unit of memory of whatever size
the native word size on the machine is. I think BCPL (a C ancestor) had
this.

(*) Or C with MS's Windows defines in place.

--
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...


James Kuyper 05-21-2012 10:24 PM

Re: Void variables
 
On 05/21/2012 05:53 PM, Raj Pashwar wrote:
> Hello
>
> I would like to define a variable of void type. However I get compiler
> errors:
>
> void x; // error: variable or field ‘x’ declared void
>
> Infact there is a typedef and I want to allow the defined type to be,
> void. However, the error is the same.


You're making essentially the same fundamental conceptual mistake as a
little child who says "I want a nothing. Give me a nothing! Why won't
you give me a nothing?"

Why do you think that you'd like to define a variable of void type? What
would you expect to be able to do with it? We won't be able to show you
how to define an object of void type, there's no such thing. However, if
we know what you wanted to do with it, we could probably suggest
alternative ways of achieving the same goals.


Kaz Kylheku 05-22-2012 02:18 AM

Re: Void variables
 
On 2012-05-21, Ike Naar <ike@iceland.freeshell.org> wrote:
> On 2012-05-21, Raj Pashwar <raj121190@hotmail.NOSPAM.com> wrote:
>> I would like to define a variable of void type.

>
> How would such a variable be useful?


Furthermore, among what domain values would it vary?

--
If you ever need any coding done, I'm your goto man!

88888 Dihedral 05-22-2012 06:17 AM

Re: Void variables
 
John Gordon於 2012年5月22日星期二UTC+8上午6時05分39秒 寫道:
> In <jpedgm$br1$1@speranza.aioe.org> Raj Pashwar <raj121190@hotmail.NOSPAM..com> writes:
>
> > Hello

>
> > I would like to define a variable of void type. However I get compiler
> > errors:

>
> > void x; // error: variable or field ‘x’ declared void

>
> > Infact there is a typedef and I want to allow the defined type to be,
> > void. However, the error is the same.

>
> I believe you are only allowed to declare void pointers, not plain voids.
>
> This is allowable:
>
> void *x;
>
> But not this:
>
> void x;
>
> --
> John Gordon A is for Amy, who fell down the stairs
> gordon@panix.com B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"


The type void * is useful for holding an address that supports the polymorphism in the types of the content poined by a pointer in the run time.


nick_keighley_nospam@hotmail.com 05-22-2012 07:15 AM

Re: Void variables
 
On Monday, May 21, 2012 10:53:26 PM UTC+1, Raj Pashwar wrote:

> I would like to define a variable of void type. However I get compiler
> errors:
>
> void x; // error: variable or field x declared void
>
> Infact there is a typedef and I want to allow the defined type to be,
> void. However, the error is the same.


there is no such thing as a void type. What do you think it means. If you explain we might be able to tell you how to achieve what you want some otherway.


All times are GMT. The time now is 11:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.