names of user defined functions

This is a discussion on names of user defined functions within the C++ Programming forums, part of the General Programming Boards category; Hi 1: Do we need to follow the same rules for function names as for the variables? 2: I have ...

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

    names of user defined functions

    Hi

    1: Do we need to follow the same rules for function names as for the variables?

    2: I have always noticed there is no space between the function name and the parentheses, e.g. func(). But I have just experimented and found that having a space between the function name and parentheses doesn't make a difference. Correct? Perhaps, it's considered non-standard.
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    C++ Identifiers

    There are also reserved identifiers. The standard reserves all identifiers prefixed with double underscore or an underscore followed by an uppercase letter (in any scope) and all prefixed with underscore only (in the global scope). IIRC there are others like these beginning with SIG (for signal codes).
    I never put signature, but I decided to make an exception.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by jackson6612 View Post
    Hi

    1: Do we need to follow the same rules for function names as for the variables?
    In addition to kmdv's very informative response...
    Yes, follow the same rules... use function names that make sense, keep them terse but not undescriptive of their function, try to spell things correctly.

    2: I have always noticed there is no space between the function name and the parentheses, e.g. func(). But I have just experimented and found that having a space between the function name and parentheses doesn't make a difference. Correct? Perhaps, it's considered non-standard.
    I use a space all the time... I find it much more readable that way (but then the rest of my coding style is a bit unortodox as well)
    Code:
    int AssessRisk ( int Size, int Speed )
      { int Danger = 0;
        if ( Speed > Size )
          Danger = 1;
        else
          { Size = Speed *2;
             Danger = ( Speed /= 2 ) + Size; }
        return Danger; }
    It's not one of the "standards" but I find it very easy to read.
    Last edited by CommonTater; 05-14-2011 at 04:19 PM.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,768
    I don't like the fact that the braces are at the same lines as the code. IMO, you should use a style closer to Allman or K&R. This is obfuscation.
    Regarding the paranthesises... it's just whitespace. The compiler ignores it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    254
    Thanks a lot, everyone. It was helpful.

    Regards
    Jackson
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    2,492
    as an example, the following is perfectly valid code:

    Code:
    #include <iostream>
    int
    main
    (
    int
    argc
    ,
    char
    **
    argv
    )
    {
    std
    ::
    cout
    <<
    "hello, world!"
    <<
    std
    ::
    endl
    ;
    return
    0
    ;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File names using a user defined name
    By KnightMan in forum C Programming
    Replies: 2
    Last Post: 04-11-2011, 08:28 PM
  2. User-defined functions
    By naya22 in forum C++ Programming
    Replies: 6
    Last Post: 04-10-2007, 11:25 AM
  3. User defined functions
    By alexpos in forum C Programming
    Replies: 2
    Last Post: 10-23-2005, 02:53 PM
  4. New to user defined functions
    By Extropian in forum C Programming
    Replies: 4
    Last Post: 08-15-2005, 10:45 PM
  5. Help! User defined functions
    By AdrenalinFlow in forum C Programming
    Replies: 3
    Last Post: 02-22-2003, 06:36 PM

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