CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Location
    Linköping, Sweden
    Posts
    261

    Does this conform to the ISO standard?

    Hi. I was helping a friend yesterday who needed to set up a compiler on her home computer in order to do some labwork for a course in OS programming.

    I looked through part of the code for the lab skeleton because it refused to compile, and I found many strange things. One thing, however, made me hesitate as to whether this lab skeleton even conforms to the standard at all, namely the following:
    Code:
    main(argc, argv)
    int argc;
    char *argv[];
    {
    <stuff>
    }
    Note the lack of return type for main, the lack of type for the parameters and the odd decision to specify the headers between the parameter list and the function definition. Is this even allowed in C or does it cause undefined behaviour?
    Errare humanum est, ergo non sum humanus.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Does this conform to the ISO standard?

    Quote Originally Posted by Hnefi
    Hi. I was helping a friend yesterday who needed to set up a compiler on her home computer in order to do some labwork for a course in OS programming.

    I looked through part of the code for the lab skeleton because it refused to compile, and I found many strange things. One thing, however, made me hesitate as to whether this lab skeleton even conforms to the standard at all, namely the following:
    Code:
    main(argc, argv)
    int argc;
    char *argv[];
    {
    <stuff>
    }
    Is this for 'C' (not C++)?

    If this is 'C' this is old-style K&R function definition, and is valid (but hardly any programs use this, except for those 'C' programs that were written somehwere around 20 or so years ago).

    None of this is valid C++, however. You need a return type for main(), and old-style K&R function headers are forbidden.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Jul 2003
    Location
    Linköping, Sweden
    Posts
    261

    Re: Does this conform to the ISO standard?

    I see. Yes, judging from the rest of the code, it's C. Your observation that this looks like old code probably explains why the rest of the source seems so arcane in some places. We'll see how I'll be able to tackle it when it's time for me to take the course next year.

    Thanks for your help.
    Errare humanum est, ergo non sum humanus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured