write a function that returns true

This is a discussion on write a function that returns true within the C Programming forums, part of the General Programming Boards category; Code: static void sramDbgParse(void) { if (SRCopy.flag == 0x5c) { printf("\r\nWatchdog flag seen. Prev pc/lr/prc_cur: "); printf(Copy.last_pc); printf(Copy.last_lr); printf(Copy.last_prc); printf("\r\n"); ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    7

    write a function that returns true

    Code:
    static void sramDbgParse(void)
    {
        if (SRCopy.flag == 0x5c) {
    	printf("\r\nWatchdog flag seen.  Prev pc/lr/prc_cur: ");
    	printf(Copy.last_pc);
    	printf(Copy.last_lr);
    	printf(Copy.last_prc);
    	printf("\r\n");
        }
    }
    if flag 0x5c is met, return true

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    .. is that a question?

    edit - I'm just going to say this before this thread turns into the same thing as your first thread: Give us all the details of what you're trying to do, and then ask a very specific question.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    And more specifically, how do you propose to return anything from a void function with a void parameter list?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,762
    > .. is that a question?
    if this is an answer
    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.

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    how do you propose to return anything from a void function with a void parameter list?
    Judging by the global variable that's in there, my best bet is they just need to add this line to the end and change the return type:

    Code:
    return SRCopy.flag == 0x5c;

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by sean View Post
    and change the return type:
    I think that was my point.

    (Or alternatively, there may be something other part of SRCopy that needs to be set to true, I suppose, but I have no idea what it could be, because I don't know what SRCopy is, which was your point.)

  7. #7
    Registered User
    Join Date
    Jul 2009
    Posts
    7
    my question is valid as in:
    - the function above is called by in another module and works fine so, don't get all caught up with that.

    Question was:
    -- write a new function that would check the validity of 0x5C and return true if it's flagged as set or not set

    if it's set the I would use the new return function to log a counter in memory

    hope that is clear

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So then do that. What's the problem? (After all, if you've got C99, you've got "true" and "false" already.)

  9. #9
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You already check if that's set... why don't you just return the outcome of that expression? It seriously can't be any simpler...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 09:28 AM
  2. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

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