Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 29-05-2009
Member
 
Join Date: Feb 2008
Posts: 214
What is Generic Pointer?

Hi,

I want to know about generic pointer.
Can someone please let me know about the term Generic Pointer with a simple example.
Reply With Quote
  #2  
Old 29-05-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: What is Generic Pointer?

When a variable is declared as being a pointer to type void it is known as a generic pointer. Since you cannot have a variable of type void, the pointer will not point to any data and therefore cannot be dereferenced. It is still a pointer though, to use it you just have to cast it to another kind of pointer first. Hence the term Generic pointer.

This is very useful when you want a pointer to point to data of different types at different times.

Code:
int
main()
{
  int i;
  char c;
  void *the_data;

  i = 6;
  c = 'a';

  the_data = &i;
  printf("the_data points to the integer value %d\n", *(int*) the_data);

  the_data = &c;
  printf("the_data now points to the character %c\n", *(char*) the_data);

  return 0;
}
Reply With Quote
  #3  
Old 29-05-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: What is Generic Pointer?

Functions using generic pointers implement common utility for almost all objects of various types. One such function is the standard memcmp() function which compares the objects pointed by s1 and s2, in the below declaration, for equality. Its prototype is:

Code:
#include <string.h>
int memcmp(const void *s1, const void *s2, size_t n);
Internally, it casts s1 and s2 to pointers to character (signed or unsigned), and compares character-by-character till either of the following conditions occurs:
a. characters pointed by character pointers are not equal; returns with a nonzero value
b. all n character pointed by internal character pointers have been compared to be equal; returns with 0
Reply With Quote
  #4  
Old 29-05-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: What is Generic Pointer?

A "generic pointer" is not a specific term in programming C/C++ although it may, perhaps, be represented by a void *.

A void * is a pointer to a memory location without actually specifying what data that location stores.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is Generic Pointer?"
Thread Thread Starter Forum Replies Last Post
Changing Stylus pointer to normal Pointer in Tablet PC Kelley Portable Devices 3 21-06-2011 07:22 PM
Parameter function and generic pointer Rubero Software Development 7 25-09-2010 09:04 PM
Can we use pointer in C#? Zoey Mod Software Development 5 29-01-2010 10:49 AM
Differentiation between void pointer and null pointer Ram Bharose Software Development 5 18-01-2010 12:11 PM
Pointer to structure in C Jamaima Software Development 3 08-10-2009 03:30 PM


All times are GMT +5.5. The time now is 03:06 AM.