LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-30-2009, 07:08 PM   #16
charlitos
Member
 
Registered: Feb 2009
Posts: 51

Original Poster
Rep: Reputation: 16
Question


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

Rep: Reputation: 108Reputation: 108
Quote:
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, 06:24 AM   #18
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
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.
 
  


Reply

Tags
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 08:10 PM
what are void pointers used for? aditya1 Linux - General 10 03-14-2005 04:06 PM
void pointers suchi_s Programming 9 11-08-2004 04:05 PM
void main(void) linuxanswer Programming 4 10-26-2003 01:37 AM
void foo(void) and void foo() lackluster Programming 9 02-15-2003 11:57 AM


All times are GMT -5. The time now is 06:37 AM.

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