Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. comparing two void* values

comparing two void* values

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amr Shahin
    wrote on last edited by
    #1

    hi every1 im writing a code that needs to compare two poitner of type (void *) i dont know how to do that; i tries to use the memcmp function but it requires a length parameter ! thanks already

    T J 2 Replies Last reply
    0
    • A Amr Shahin

      hi every1 im writing a code that needs to compare two poitner of type (void *) i dont know how to do that; i tries to use the memcmp function but it requires a length parameter ! thanks already

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      same question[^], same answers... templates are what you need. you cannot know what kind of object is pointed to by a void* address...

      1 Reply Last reply
      0
      • A Amr Shahin

        hi every1 im writing a code that needs to compare two poitner of type (void *) i dont know how to do that; i tries to use the memcmp function but it requires a length parameter ! thanks already

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #3

        If you need to compare the pointer values, just compare them using normal operators.  If you need to compare the things that the pointers point to you need more information about them:

        int iValueA = 1;
        int iValueB = 1;

        void *vp1 = &iValueA;
        void *vp2 = &iValueB;
        void *vp3 = &iValueA;

        if( vp1 == vp3 )
        {
            OutputDebugString( _T( "vp1 == vp3\n" ) );
        }
        if( vp1 == vp2 )
        {
            OutputDebugString( _T( "vp1 == vp2\n" ) );
        }
        if( *(int*)vp1 == *(int*)vp2 )
        {
            OutputDebugString( _T( "*vp1 == *vp2\n" ) );
        }

        Peace! [edit] Alright - who is the buttmonkey that voted this a 2 with no reason given? ;P [/edit] -=- James


        If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        DeleteFXPFiles & CheckFavorites (Please rate this post!)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups