Thread: Quick Q - Typedefing integers

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    73

    Quick Q - Typedefing integers

    Hey everyone.

    I have this line...
    Code:
    typedef int ProcessHandleType;
    and I pass it to my SystemType's member functions when i want to do something to one of its processes. The reason I want to use ProcessHandles is that a handle must be one larger than an index. So if the process's index is 1, then the handle is 2. If the index is 0, the handle is 1. The reason for this is that I want to be able to, in my code, check if the handle is valid by saying...
    Code:
    ProcessHandleType Handle = System.Add( MainInitialize() );
    if( !Handle )
    {
       cout << "Couldn't add main process." << endl;
       return 1;
    }
    But the problem is that in the SystemType's functions, it accepts ProcessHandleTypes but it will also accept plain integers!

    Long question short, how do I make it so I can typedef an integer as a ProcessHandleType, but not be able to pass integers when a function accepts a ProcessHandleType?

    Thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    That seems a poor reason for fudging data types.

    Code:
    ProcessHandleType Handle = System.Add( MainInitialize() );
    if( ! isValidHandle(Handle) )
    {
       cout << "Couldn't add main process." << endl;
       return 1;
    }
    Then most of the code doesn't care about how you choose to implement Handles
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Long question short, how do I make it so I can typedef an integer as a ProcessHandleType, but not be able to pass integers when a function accepts a ProcessHandleType?
    There seems to be some confusion here about what typedef does. ProcessHandleType (the way you've defined it) is an integer, you've just come up with a new name for it. The compiler will see absolutely no difference between (for example):
    Code:
    ProcessHandleType handle1 = 3; // and
    int handle2 = 3;
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  3. Integers into array.
    By livestrng in forum C Programming
    Replies: 10
    Last Post: 10-29-2008, 11:35 PM
  4. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 10:33 AM
  5. Replies: 6
    Last Post: 08-04-2003, 10:57 AM