Please help this void function...

This is a discussion on Please help this void function... within the C Programming forums, part of the General Programming Boards category; Hey. Just look at the codes and give an advice please. Code: BOOL checkPortNum(U32 port) { if(port < 0 || ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    3

    Please help this void function...

    Hey. Just look at the codes and give an advice please.

    Code:
    BOOL checkPortNum(U32 port)
    {
        if(port < 0 || port > 4)
        {
          return (ERROR);
        }
        else{
        return (SUCCESS);
        }
    }
    BOOL checkPinNum(U32 pin)
    {
        if(pin < 0 || pin > 0xFFFFFFFF)
        {
          return (ERROR);
        }
        else{
          return (SUCCESS);
          }
    and here is problem...
    Code:
    PUBLIC void drvGpioDirection(U32 port, U32 pin, PinDirection direction)
    {
        if (checkPort(port) && checkPin(pin))
        {
        GPIO_SetDir(port, pin, direction);
        }
        else 
        WHAT???
    }

  2. #2
    Registered User
    Join Date
    Jul 2012
    Posts
    3
    I mean that how can I stop the func (drvGpioDirection) in WHAT line???
    Last edited by Salem; 12-02-2012 at 12:24 AM. Reason: font colour adds nothing, except my headache

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by ahmetalncak View Post
    I mean that how can I stop the func (drvGpioDirection) in WHAT line???
    return?

    First, the code is C++, not C, so you're in the wrong forum.

    Second, your description is isn't really clear.
    Last edited by Salem; 12-02-2012 at 12:24 AM. Reason: font colour adds nothing, except my headache

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,261
    Quote Originally Posted by Adak View Post
    First, the code is C++, not C, so you're in the wrong forum.
    The code is neither C nor C++.
    Right 98% of the time, and don't care about the other 3%.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    Granted it's missing a closing brace and the #defines for several things, but it looks perfectly feasible that this is C to me. I'm baffled why anyone is saying otherwise.

    Do whatever you want to do: return, exit, nothing... those are the three most obvious choices right there.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,261
    Quote Originally Posted by iMalc View Post
    Granted it's missing a closing brace and the #defines for several things, but it looks perfectly feasible that this is C to me. I'm baffled why anyone is saying otherwise.
    I wouldn't have commented, except for Adak's incorrect assertion that it was C++ rather than C. Yes, it is feasible it is C (or C++), if the points you've described are addressed.

    Although there aren't many feasible meanings of that "PUBLIC" in front of one function other than nothing, or a compiler-specific extension.
    Right 98% of the time, and don't care about the other 3%.

  7. #7
    Registered User
    Join Date
    Nov 2012
    Posts
    1,063
    The question seems to be about how to handle errors. If the condition

    (checkPort(port) && checkPin(pin))

    is true, then all is well and the program proceeds. If it's not, then it's up to you to decide what's appropriate. For example, it might be appropriate to delay for some short time and then check the pin and port again - maybe that device was momentarily unavailable. If this strategy continues to fail then at some point you have to give up.

    Since it's a void function, you have the option of doing nothing, as was mentioned. This means that any error (like when the port and pin are not both returning SUCCESS) would just be ignored.

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    Quote Originally Posted by grumpy View Post
    I wouldn't have commented, except for Adak's incorrect assertion that it was C++ rather than C. Yes, it is feasible it is C (or C++), if the points you've described are addressed.

    Although there aren't many feasible meanings of that "PUBLIC" in front of one function other than nothing, or a compiler-specific extension.
    Understood.
    I would guess that PUBLIC is defined as extern, and/or something like a dllexport specification.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,344
    I base this on nothing, because you have not given sufficient information about your problem

    It seems like you are setting up a data-direction register, and if checkPort(port) && checkPin(pin), you don't want to change the data-direction.

    Depending on what checkPort(port) && checkPin(pin) is checking determines what you want to do.

    If the device is detecting a signal on the input pin, and the if statement is to protect against the microchip driving the line high/low when the input differs, you want to make sure that it remains an input

    Maybe something like this is what you want...

    Code:
    PUBLIC void drvGpioDirection(U32 port, U32 pin, PinDirection direction)
    {
      if (checkPort(port) && checkPin(pin))
      {
        GPIO_SetDir(port, pin, direction);
      }
      else
      {
        GPIO_SetDir(port, pin, GPIO_INPUT);
      }
    Where GPIO_INPUT has been defined as the default value for an input
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. difference between void and static void function
    By mahaju in forum C++ Programming
    Replies: 7
    Last Post: 12-27-2011, 03:02 AM
  2. Replies: 12
    Last Post: 03-27-2009, 02:36 PM
  3. Passing a variable in void to another void function
    By stevedawg85 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 06:17 PM
  4. void, void function
    By Furious_George in forum C++ Programming
    Replies: 4
    Last Post: 10-14-2003, 05:04 PM
  5. void non void function
    By modance in forum C Programming
    Replies: 6
    Last Post: 01-28-2003, 07:06 AM

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