Results 1 to 4 of 4

Thread: What is Generic Pointer?

  1. #1
    Join Date
    Feb 2008
    Posts
    216

    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.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    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;
    }

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    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

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    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.

Similar Threads

  1. Changing Stylus pointer to normal Pointer in Tablet PC
    By Kelley in forum Portable Devices
    Replies: 3
    Last Post: 21-06-2011, 07:22 PM
  2. Parameter function and generic pointer
    By Rubero in forum Software Development
    Replies: 7
    Last Post: 25-09-2010, 09:04 PM
  3. Can we use pointer in C#?
    By Zoey Mod in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 10:49 AM
  4. Differentiation between void pointer and null pointer
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 18-01-2010, 12:11 PM
  5. Pointer to structure in C
    By Jamaima in forum Software Development
    Replies: 3
    Last Post: 08-10-2009, 03:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,043,184.93571 seconds with 16 queries