cin/cout vs. scanf/printf

  • Thread starter Podrzut_z_Laweczki
  • Start date
D

Default User

Victor said:
Since the size of 'size_t' (which is its own type, not a typedef for
anything) is implementation-defined, you should consider looking for
an implemenation-specific solution. For example, in Win64 casting
to unsigned long is not going to work very well. Microsoft did add
the I64 specifier (IIRC) for printing out types that are longer than
unsinged long.

That's a way, but in my mind needless unportability. When used for its
intended purpose, holding a size of an object, size_t is very rarely
going to have a value larger than ULONG_MAX.




Brian
 
F

Frederick Gotham

Noah Roberts posted:
A common C definition of main is:

main()
{
return 0;
}


That's valid in C89.

In C99, the implicit return value of "int" no longer applies.

Furthermore, in C, empty parentheses only specify a variable length
argument list if it's a declaration:

void Func(); /* Might be variable length */

void Func() /* Takes no arguments */
{

}

The most "proper" way of defining main in C is:

int main(void) {...

Although there's nothing wrong with:

int main()

(But they'd don't like empty parentheses.)
 
D

Default User

Noah said:

Actually, the FAQ supports what Victor said.

The C99 Standard says:

5.1.2.2.1 Program startup

[#1] The function called at program startup is named main.
The implementation declares no prototype for this function.
It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv,
though any names may be used, as they are local to the
function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;8) or in some other implementation-defined
manner.

I know why you believe it is, and maybe the faq is wrong...it's the
only authority I could find. A common C definition of main is:

main()
{
return 0;
}

Common doesn't make it correct.
I was trying to find something that speaks to the unspecified nature
of the accepted parameters in that declaration but couldn't coax
google into giving me any. The FAQ would lead one to believe it is
ok.

That what is ok? Leaving out the void? It doesn't say that.



Brian
 
D

Default User

Default said:
Actually, the FAQ supports what Victor said.

From your follow-up question on comp.lang.c, I understand now what you
were getting at. Disregard this.



Brian
 
N

Noah Roberts

Default said:
The C99 Standard says:

5.1.2.2.1 Program startup

[#1] The function called at program startup is named main.
The implementation declares no prototype for this function.
It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv,
though any names may be used, as they are local to the
function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;8) or in some other implementation-defined
manner.

Ok, this is getting a little OT so I'm labeling it such...

That last statement is something I find interesting. Assuming that
"implementation-defined" is the same in C as it is in C++ then by that
statement "void main()" would be perfectly /valid/ (even if not
portable) in some implementation that defines it as being such.
 
D

Default User

Noah said:
Default said:
The C99 Standard says:

5.1.2.2.1 Program startup

[#1] The function called at program startup is named main.
The implementation declares no prototype for this function.
It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv,
though any names may be used, as they are local to the
function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;8) or in some other implementation-defined
manner.

Ok, this is getting a little OT so I'm labeling it such...

That last statement is something I find interesting. Assuming that
"implementation-defined" is the same in C as it is in C++ then by that
statement "void main()" would be perfectly valid (even if not
portable) in some implementation that defines it as being such.


I assume so. The C++ standard is a bit firmer in that regard, mandating
the return type but allowing the rest of the type to be
implementation-defined. This is, I assume, to support legacy stuff like
the env parameter. I don't know that C was trying specifically to allow
void return types, but frankly I don't see it as precluding them either.




Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top