without using ';'

This is a discussion on without using ';' within the C Programming forums, part of the General Programming Boards category; any pgm will write without using semicolon in c;...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    9

    Question without using ';'

    any pgm will write without using semicolon in c;

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    #include <stdio.h>
    
    int main()
    {
       if (printf("Hello, World\n")) {}
    }
    However, the above code is incorrect in that it doesn't return a value which it should.

    --
    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.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    9
    thank u mats;any usefull without using ';'?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by arul View Post
    thank u mats;any usefull without using ';'?
    Why? Semicolon is part of the language, you "have to" use it. We can contrive examples that show that you can write something fairly complicated without the semicolon, but it's still going to be contrived. You can probably write a long book without using the letter q, but it would be hard work, and only useful in the sense that you can write a long book without using the letter q.

    --
    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.

  5. #5
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    usefull? you mean without using "if"?
    gavra.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    > However, the above code is incorrect in that it doesn't return a value which it should.

    Except under C99.

    Here's C89:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void func(void)
    {
        if (printf("Something")) {}
    }
    
    int main()
    {
        if(atexit(func)) {}
        if(exit(EXIT_SUCCESS)) {}
    }
    edit: nevermind, exit returns void.
    Last edited by robwhit; 07-29-2008 at 08:28 AM.

  7. #7
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    ^ things tend to change with the time..
    gavra.

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    9
    thank u robwhit

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    It's invalid. Nevermind.

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Are you trying to write code without semicolons because your semicolon key broken or something?

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by cpjust View Post
    Are you trying to write code without semicolons because your semicolon key broken or something?
    That was my original comment in post #4, but I deleted it before I event submitted the reply - it's just pointless.

    --
    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

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