Thread: function declared inside other

  1. #16
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Elysia View Post
    The compiler would assume a default prototype of
    int fnc(...)
    So no type checking on the arguments and the return type is int.
    (If a proper declaration is not found before call.)
    ok. the compiler only assumes default type int when no declaration is found prior to calling and.is that what u mean?and what about the arguments listed in the call?

  2. #17
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by BEN10 View Post
    so what i understood till now is that any function's scope is from the point it is declared till the end of the file.i mean if i declare any function(say f1()) inside any other function(say f2()) then i can use f1() from the point of declaration to the end of the file whether i call it in some other function's definition.if i call f1() from any other fucntion defined before f2() then it'll be an error.
    yep! that's it

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by BEN10 View Post
    ok. the compiler only assumes default type int when no declaration is found prior to calling and.is that what u mean?
    Yes.

    and what about the arguments listed in the call?
    Nothing. The compiler assumes that the prototype takes an infinite number of arguments, such as:
    int myfunction();
    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.

  4. #19
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by BEN10 View Post
    ok. the compiler only assumes default type int when no declaration is found prior to calling and.is that what u mean?and what about the arguments listed in the call?
    they are compared 1-to-1 with the function parameters

  5. #20
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Elysia View Post
    Yes.



    Nothing. The compiler assumes that the prototype takes an infinite number of arguments, such as:
    int myfunction();
    hmm...that's why we should explicitly write int myfunc(void) to make the function not take any arguments.and is this(compiler's assunption) the reason for the compiler not showing any error while i used getch() without its proper header.
    Last edited by BEN10; 04-20-2009 at 10:48 AM.

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, you need to do that in prototypes, otherwise the compiler assumes it takes an infinite number of arguments.
    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.

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by BEN10 View Post
    hmm...that's why we should explicitly write int myfunc(void) to make the function not take any arguments.and is this(compiler's assunption) the reason for the compiler not showing any error while i used getch() without its proper header.
    If you enable warnings, which is generally a good idea, it will warn you for not having a prototype.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer to a class inside the WindowsProcedure function
    By like_no_other in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2009, 12:52 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM