Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Void variables

Reply
Thread Tools

Void variables

 
 
Raj Pashwar
Guest
Posts: n/a
 
      05-21-2012
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
 
Reply With Quote
 
 
 
 
John Gordon
Guest
Posts: n/a
 
      05-21-2012
In <jpedgm$br1$> Raj Pashwar <> 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
B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

 
Reply With Quote
 
 
 
 
Ike Naar
Guest
Posts: n/a
 
      05-21-2012
On 2012-05-21, Raj Pashwar <> wrote:
> I would like to define a variable of void type.


How would such a variable be useful?
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-21-2012
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
 
Reply With Quote
 
Joe Pfeiffer
Guest
Posts: n/a
 
      05-21-2012
Raj Pashwar <> 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?
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      05-21-2012
In article <>,
Ian Collins <ian-> 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...

 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      05-21-2012
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.

 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      05-22-2012
On 2012-05-21, Ike Naar <> wrote:
> On 2012-05-21, Raj Pashwar <> 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!
 
Reply With Quote
 
88888 Dihedral
Guest
Posts: n/a
 
      05-22-2012
John Gordon於 2012年5月22日星期二UTC+8上午6時05分39秒 寫道:
> In <jpedgm$br1$> Raj Pashwar <..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
> 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.

 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      05-22-2012
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.
 
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
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57