Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-30-2009, 06:08 PM   #16
Registered: Feb 2009
Posts: 51

Original Poster
Rep: Reputation: 16

what if i want data type abstraction like templates on C++ ?
Old 03-31-2009, 02:43 AM   #17
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Originally Posted by charlitos View Post
what if i want data type abstraction like templates on C++ ?
That would be a good reason to use void*.
Old 03-31-2009, 05:24 AM   #18
Sergei Steshenko
Senior Member
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Originally Posted by raconteur View Post
Doesn't anybody use unions any more? I'm starting to feel a bit like a dinosaur here...

Back on topic: IMO, void pointers are quite useful in the right conditions. I agree that they need to be used only where necessary, and not as a catch-all convenience but I have several classes where their polymorphic properties would not be possible without void pointers. Bad practice? I think not, just another tool.
Union was my initial thought, and I rejected it.

The point is that union would allocate one memory area/location for the structures/pointer to them, and in such a case the need to differentiate between the two entities still remains, i.e. a, say, flag is needed.

So I decided to use two pointers per two type possibilities, and the fact that NULL pointer means unused pointer.


pointer, void

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Generic Function Pointers In C And Void * LXer Syndicated Linux News 0 02-22-2009 07:10 PM
what are void pointers used for? aditya1 Linux - General 10 03-14-2005 03:06 PM
void pointers suchi_s Programming 9 11-08-2004 03:05 PM
void main(void) linuxanswer Programming 4 10-26-2003 12:37 AM
void foo(void) and void foo() lackluster Programming 9 02-15-2003 10:57 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:40 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration