#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    30
    Rep Power
    2

    Function Arguments


    Why can't I put semicolons in the function arguments just like

    Code:
    void foo(int x;);
    Is int x not considered a statement that's why it does not have ";"?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,396
    Rep Power
    1871
    Maybe you should read a book or something - you know, something which explains the syntax of the C language.

    Because this is now your 3rd thread (at least) where you've asked basically the same question.
    http://forums.devshed.com/c-programm...ns-948801.html
    http://forums.devshed.com/c-programm...on-948762.html
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    26
    Rep Power
    0
    because in functions comma is used to seperate the arguements in c.i think you should know about the basic syntaxes of c.try googling or buy some books.all the best to get a better knowledge in c.who knows you may be the next person who can develop operating systems like bill gates
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    95
    Rep Power
    4
    ; is for end of statement and function argument is not end of statement.
    and we use , to separate arguments.

    Comments on this post

    • jwdonahue agrees
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    As eramit2010 pointed out, semicolons are how we tell the compiler where the end of the statement is. In C/C++/C#, any extra white space is ignored. So:

    Code:
    void
    foo
    {
    int
    x
    )
    ;
    is equivalent to:

    Code:
    void foo( int x ) ;
    So the compiler scans the source code for the next semicolon before attempting to parse the input for further processing. As it parses the statement, it adds a parameter list to the func->name->foo node of the abstract syntax tree (AST) when it encounters the opening parens, if it then encounters the semicolon before the closing parens, it has reached the end of the statement before the parameter list is completed and emits a syntax error as it removes the current node from the AST.

    Another way to look at it:

    Code:
    int x ; // Is a complete statement.
    
    (int x;) // Is an incomplete statement.
    Last edited by jwdonahue; July 24th, 2013 at 10:15 PM. Reason: Code tags around the final example.
    I no longer wish to be associated with this site.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Statements can be enclosed by curly braces {} not parens ().

    Comments on this post

    • eramit2010 agrees : :)
    I no longer wish to be associated with this site.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    109
    Rep Power
    3
    Just syntax. I don't think about it too much, just remember it.

    Comments on this post

    • jwdonahue disagrees : Not edifying, me-too post.

IMN logo majestic logo threadwatch logo seochat tools logo