A newbie's code

C

CBFalconer

Bill said:
That's absurd. The very first program anyone learns is:

#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}

There are certainly people who will argue that it should
be written with puts instead of printf, but printf is generally
introduced right at the start.

If you mean that people shouldn't write variadic functions
until they know how, I would agree. But simply avoiding
them out of hand would be severely restrictive.

Variadic functions are dangerous because there is no way to check
that they are called correctly, especially when the format string
for printf is a variable. Better languages ensure that all
parameters are properly typed and checked. Pascal achieves the
same effect without the vulnerabilities, by specifying a standard
abbreviation for multiple simple calls. Unfortunately the
successors to Pascal, which include Modula and Ada, do not have
this simple and reliable mechanism.
 
C

Clark S. Cox III

Bill said:
That's absurd. The very first program anyone learns is:

#include <stdio.h>
int
main(void)
{
printf("Hello, world!\n");
return 0;
}

There are certainly people who will argue that it should
be written with puts instead of printf, but printf is generally
introduced right at the start.

If you mean that people shouldn't write variadic functions
until they know how, I would agree. But simply avoiding
them out of hand would be severely restrictive.
I should have been more specific. Yes, avoiding *writing* them is
generally a good idea. Also note that I said "generally" not "always".
 
D

Dave Thompson

Variadic functions are dangerous because there is no way to check
that they are called correctly, especially when the format string
for printf is a variable. Better languages ensure that all
parameters are properly typed and checked. Pascal achieves the
same effect without the vulnerabilities, by specifying a standard
abbreviation for multiple simple calls. <snip>

For the builtin {read,write}{,ln} it does, but AFAIKaCT there is no
(standard) way to do this for user-written routines.

- David.Thompson1 at worldnet.att.net
 
C

CBFalconer

Dave said:
For the builtin {read,write}{,ln} it does, but AFAIKaCT there is no
(standard) way to do this for user-written routines.

Thus avoiding the insecurities of variadic functions. How often do
you really need a user-written variadic function?
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,264
Latest member
FletcherDa

Latest Threads

Top