Thread: Passing an int as an parameter for a pointer argument

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    15

    Passing an int as an parameter for a pointer argument

    I was debugging my program and I accidentally pointed an int as a parameter for a pointer object. Am I wrong in thinking doing this should issue a warning by the compiler?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Let me see now... where did I put that crystal ball?

    Ahhh... there it is... Just give it a little shining up...

    Focus in on vexed .... sorry: "Error, signal too weak for clear image"....

    Care to try again, maybe post the problem code this time?
    << !! Posting Code? Read this First !! >>

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    15
    I meant in the general case. For instance:

    If given a methodA, declared here:

    methodA(Pointer* p, int a) {
    }

    And a methodB that calls methodA:

    methodB() {
    methodA(blah1, &blah2);
    }

    where blah1 and blah2 are both ints, should compiling this code produce a warning? I know that C isn't as strict on type checking but I find weird (as a new C programmer) that in my case it didn't.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It should result in a warning. If it does not, you probably failed to provide a declaration (that is either a prototype or a definition) for methodA before the definition of methodB.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Post your code in code tag.
    It's well not method, but function.
    What compiler are you using?
    Read your compiler documentation, how to enable warning(level) etc.

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    15
    Thanks for the responses! After thinking about prototype/definition, I looked into my header file and realized that the prototype for function methodA was incorrectly written as described in methodB.

    Dang, that is embarrassing. Guess my noob sign definitely rang out haha (calling them methods rather than functions).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting Issue?
    By matthewlane in forum C Programming
    Replies: 1
    Last Post: 11-15-2010, 05:55 PM
  2. i need help with this question:
    By marcuspax in forum C Programming
    Replies: 16
    Last Post: 08-16-2010, 08:12 AM
  3. Passing Argument from incompatible pointer type
    By AmritxD in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 03:23 PM
  4. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  5. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM