C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 10th, 2002, 03:05 PM
Neildadon Neildadon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 12 Neildadon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
what do the different voids do?

Can anyone explain to me the purpose of using void and the different ways to use it when using functions?

Reply With Quote
  #2  
Old June 10th, 2002, 08:28 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,589 Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 40 m 58 sec
Reputation Power: 1001
Basically, the void keyword is used to specify that a function takes (or returns) no parameters, depending on where you put it. For example:

int function1(void);
void function2(int, char);
void function3(void);

In the above example, function1 takes no arguments and returns an int, function2 takes 2 arguments, but returns nothing and function3 takes no arguments and returns no arguments.

The one special case is the void pointer (void *), which does actually return (or take) a generic pointer, but you have to type cast the pointer to another type, before using it. A commonly used function of this type is the malloc() function which is prototyped something like this:
void *malloc(int n_bytes)

and the usage goes something like this:
Code:
int *i;
char *c;

i = (int *)malloc(50 * sizeof(int)); /* Allocate 50 integer array */
c = (char *)malloc(20 * sizeof(char)); /* Allocate 20 char array */

Reply With Quote
  #3  
Old June 18th, 2002, 02:13 PM
chance chance is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 4 chance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Another usage is void *.

This really is completely different than a void.

if x is declared as:

void *x;

then x is a pointer to "nothing" (some unknown thing).


if something is a pointer to nothing, that means it could be
a pointer to anything. Its up to you to know the right thing
to cast it to. Don't do this until you understand exactly why
you would need to. Even then think about it for ten minutes
and try to talk yourself out of it.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > what do the different voids do?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT