Thread: function prototyping

  1. #31
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    True, but what if you forget what arguments it takes or what order?
    Myself, I cannot remember exactly what or in what order arguments must be passed. But when typing out the function name, I clearly see what the arguments names are and thus I can pass the correct arguments and in order.
    It is more of a reminder than actual documentation, but it is very helpful. And sometimes it even makes it so that I do not need to read the documentation.
    This is the main purpose of putting names in prototypes according to me. Is that a waste of space?
    You do need those prototypes anyway, so copy and paste is easier.

    I also take shortcuts with not typing out stuff too, but not at such a point where it becomes unreadable. In my opinion, stripping the names of the parameters in prototypes reduces readability. And therefore, I do not do it.
    Usually, readability comes before duplicate / unnecessary code.
    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.

  2. #32
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    // ..._t suffix is reserved nervermind, this is an example
    I think it's only reserved by POSIX, not ANSI. http://bytes.com/groups/c/668814-usi...fixes-typedefs
    Nevertheless, it's probably a good idea to avoid it. I usually use the suffix "_type_t" myself.
    (This is going to start another debate about naming conventions, I just know it.)

    FWIW, here's what I think. I agree with Elysia here in that I think parameter names should be included in prototypes (otherwise I wouldn't have linked to the wiki page in the first place). I think it makes them easier to read, because your eye is used to parsing function definitions, and why should prototypes be any different?

    Named parameters are also useful in distinguishing two variables of the same type. While I realize that this information can be found in source code as well, it's often much easier to find a header file than a source file.

    I also think that there's no really good reason to remove the variable names. I mean, most of the time the prototype is just copied and pasted from the definition, or vise versa, at least in my code. I don't think it's unnecessary duplication, because it can be useful and it doesn't usually involve any extra effort on the part of the programmer.

    Most of this has already been said before, I know; I just thought I'd chime in with my opinion.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #33
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    About _t:
    I think it's only reserved by POSIX, not ANSI
    Indeed, more references for those interested:
    http://www.gnu.org/software/libtool/...ved-Names.html
    http://www.opengroup.org/onlinepubs/...chap02_02.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM