unconventional pointer values

This is a discussion on unconventional pointer values within the C++ Programming forums, part of the General Programming Boards category; Hi.. Well my problem is this: In C I had some code like this: Code: int function(int fake_ptr) { someType ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    unconventional pointer values

    Hi..
    Well my problem is this: In C I had some code like this:

    Code:
    int function(int fake_ptr)
    {
        someType *pointer = fake_ptr;
        
        /* More code here */
    
        return some;
    }
    where "fake_ptr" contained the address of some variable of type "someType" and it was passed to "function". I had to do this because I couldn't pass directly a pointer of "someType" type to "function". And in C it worked very well.

    But now I tried to do the same in C++ but the compiler got this error:

    " invalid conversion from 'int' to 'someType*' "

    So I would like to know if there is some way to solve this without pass directly a "someType" pointer to "function" but a int variable by containing the address of some "someType" variable in C++ ??

    I hope you have understand me... sorry for my bad english
    Last edited by nmxnmx; 02-18-2006 at 06:54 PM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    reinterpret_cast
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    How about telling us what you're trying to do?
    Because a newbie needing to use reinterpret_cast in C++ is a sure sign of something going badly wrong.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    And passing an address in an int is a sure way not to have 64-bit compatibility.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    How can your compiler not allow you to pass a someType pointer to your function? That sounds very strange to me. To check if you've done things correctly, did you declare the formal parameter as illustrated in red below?
    Code:
    int function(someType* fake_ptr)
    {
        someType *pointer = fake_ptr;
        
        /* More code here */
    
        return some;
    }

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I suspect it's a callback with an established prototype. Happens in Win32 programming all the time.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    4
    Hi again, well I can't pass a someType pointer but not for my compiler, but I'm need to link C++ code to a software named LabView, in that software you can call some dll's made in any language (like C/C++), but when you configure it, it only allows some basic type of parameters (int, float, char*) but not some complex parameter or others types that the basics (and others from it owns)..

    That's why in complex data I passed addresses to pointer of "someType" in int variables in C but it doesn't work in C++

    So I hope you can understand me and again sorry for my bad english, and thanks in advanced...
    Last edited by nmxnmx; 02-20-2006 at 10:40 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  2. sorting with pointer of pointers to array
    By dunpealslyr in forum C++ Programming
    Replies: 6
    Last Post: 10-01-2007, 11:26 PM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  4. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21