Like Tree4Likes

#If Funtion && AnotherFunction

This is a discussion on #If Funtion && AnotherFunction within the C Programming forums, part of the General Programming Boards category; Hi as the title states I have an issue understanding what this calls for? #if One Function && another Function ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    30

    #If Funtion && AnotherFunction

    Hi as the title states I have an issue understanding what this calls for?

    #if One Function && another Function

    Does this mean if I call both functions it will begin the if statement?

    There is no sample code, just a question of formating I suppose.

    Thanks!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    Maybe you should post the smallest and simplest program that illustrates the crux of your question.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    OK.
    F_funtionA, F_FunctionB are the functions lets say.

    #if (F_funtionA && F_functionB)
    unsigned char main(unsigned char variable);
    #define F_FunctionC
    #endif


    and if I want to use the functionC do i need to call first A, b? or is there something I am not understanding about &&.

    Thanks

  4. #4
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Do you mean:

    Code:
    if( function_1() && function_2() )
      do_something();
    The && is a Boolean operator. Google it. Assuming function_1 and function_2 return a Boolean of some kind (TRUE/FALSE, 0 / non-zero), then the && operator will perform an AND operation on their results. So, for instance, if you have the following:

    Code:
    if(user_has_access() && door_is_working())
       open_door();
    In this case, the door will only open is the user has access (user_has_access returns TRUE) *AND* the door is working (door_is_working returns TRUE). Otherwise it won't do anything.

    There is a slight trick as well here that catches beginner's - C uses short-circuit evaluation. If the user_has_access call returns FALSE, then there's no point checking if the door_is_working. It won't make any difference to the outcome. So the program will NOT call door_is_working at all in that instance. Some people don't realise that and their program can go wrong because they expect it to be checked anyway.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Quote Originally Posted by ledow View Post
    Do you mean:

    Code:
    if( function_1() && function_2() )
      do_something();
    The && is a Boolean operator. Google it. Assuming function_1 and function_2 return a Boolean of some kind (TRUE/FALSE, 0 / non-zero), then the && operator will perform an AND operation on their results. So, for instance, if you have the following:

    Code:
    if(user_has_access() && door_is_working())
       open_door();
    In this case, the door will only open is the user has access (user_has_access returns TRUE) *AND* the door is working (door_is_working returns TRUE). Otherwise it won't do anything.

    There is a slight trick as well here that catches beginner's - C uses short-circuit evaluation. If the user_has_access call returns FALSE, then there's no point checking if the door_is_working. It won't make any difference to the outcome. So the program will NOT call door_is_working at all in that instance. Some people don't realise that and their program can go wrong because they expect it to be checked anyway.
    Hey thank you very much! So i should call something like:
    user_has_access=1;
    door_is_working=1;
    Then my open_door(5seconds or something) function should work? If 1 is predefines as true?

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    both #if and #endif indicate that he is talking about preprocessor directives. In that case those things are not function as such, at least not runtime functions. You would need to post what F_funtionA and F_functionB really are in order for us to be able to tell how you could get the desired outcome.
    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"

  7. #7
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    They are made up functions in a sample file like the sample code i posted above. I believe I figured it out, now just to set them = to "True" will depend on whether 1 or 0 is true.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    Quote Originally Posted by tzzr101
    They are made up functions in a sample file like the sample code i posted above. I believe I figured it out, now just to set them = to "True" will depend on whether 1 or 0 is true.
    What is a function? Define a function in code as an example.

    Frankly, I think that you are either misunderstanding something pretty basic, or simply are using the wrong terminology. That is why I asked for you to elaborate with a program earlier, but you only posted a code snippet that did not have much context.
    stahta01 and iMalc like this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Quote Originally Posted by laserlight View Post
    What is a function? Define a function in code as an example.

    Frankly, I think that you are either misunderstanding something pretty basic, or simply are using the wrong terminology. That is why I asked for you to elaborate with a program earlier, but you only posted a code snippet that did not have much context.
    Ok I have a statement like this in a header file

    #if (F_A && F_B)
    unsigned char secondary (unsigned char type);
    #define F_C
    #define F_D
    #endif

    I am trying to call for F_C and it says its undefined. I think it's because i have to first say F_A, F_B are true. I cannot put actual code due to the sensitivity of my project.

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    2,372
    @tzzr101:

    Do you know the difference between a MACRO, function, and function prototype?
    Because your questions implies you have no idea that there is is any difference between the three things.

    Tim S.
    AndiPersti likes this.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > I cannot put actual code due to the sensitivity of my project.
    So make something simple, which seems to resemble the problem, using symbols like FOO and BAR
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    Quote Originally Posted by tzzr101 View Post
    I think it's because i have to first say F_A, F_B are true. I cannot put actual code due to the sensitivity of my project.
    I find it very hard to believe that someone with C skills that are to the point of not knowing about the proprocessor could be involved in such a secretive project. If the code you're using is that important, then you would have sufficient mentoring of someone else at your company, partly to keep an eye on the new employee.

    Also, the act of hiding API methods behind such proprocessor directives is very very common practice by Microsoft, so I highly suspect its one of those. E.g. you just need to define WIN32_WINNT as some version or higher.

    Well I guess when you can't work it out and can't provide enough info here then I guess you'll consider other options.
    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"

  13. #13
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Quote Originally Posted by Salem View Post
    > I cannot put actual code due to the sensitivity of my project.
    So make something simple, which seems to resemble the problem, using symbols like FOO and BAR
    I did, its above. Thats literally the code and im trying to call the function F_C.

  14. #14
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Quote Originally Posted by stahta01 View Post
    @tzzr101:

    Do you know the difference between a MACRO, function, and function prototype?
    Because your questions implies you have no idea that there is is any difference between the three things.

    Tim S.
    No i do not. I am very new to programming. I'll check it out thanks!

  15. #15
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Quote Originally Posted by iMalc View Post
    I find it very hard to believe that someone with C skills that are to the point of not knowing about the proprocessor could be involved in such a secretive project. If the code you're using is that important, then you would have sufficient mentoring of someone else at your company, partly to keep an eye on the new employee.

    Also, the act of hiding API methods behind such proprocessor directives is very very common practice by Microsoft, so I highly suspect its one of those. E.g. you just need to define WIN32_WINNT as some version or higher.

    Well I guess when you can't work it out and can't provide enough info here then I guess you'll consider other options.
    Thanks for the harrassment. I am an intern, forced to do programming and have no skills in doing so. I don't know why, but I'm not the boss I do what I'm told. They don't help me either it's frusterating believe me. anyway thanks for the windows tip.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help on using a funtion
    By Ambuter in forum C Programming
    Replies: 5
    Last Post: 10-27-2011, 03:10 PM
  2. What's wrong with my funtion :(
    By bikr692002 in forum C++ Programming
    Replies: 8
    Last Post: 04-14-2006, 05:52 PM
  3. locate funtion
    By DanC in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2006, 02:21 PM
  4. is this funtion ok?
    By kermit in forum C Programming
    Replies: 8
    Last Post: 08-22-2003, 05:28 PM
  5. swap funtion
    By ManicC in forum C Programming
    Replies: 9
    Last Post: 11-15-2001, 06:55 AM

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