473,503 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc.

Hi,

Consider:
------------
char stringinput[64]

..bla. bla. bla.

do
{
printf("Write to result.txt (y/n)? ");
scanf("%s", stringinput);
}
while (writechar != 'y' || != 'n');
The compiler complaints. It says: error C2059: syntax error : '!='

Another problem is that MS VS 2005 keeps complaining about deprecated
commands such as:

1. warning C4996: 'fscanf' was declared deprecated.......: see
declaration of 'fscanf' - Message: 'This function or variable may be
unsafe. Consider using fscanf_s instead. To disable deprecation, use
_CRT_SECURE_NO_DEPRECATE. See online help for details.'

2. warning C4996: 'scanf' was declared deprecated: see declaration of
'scanf'... Message: 'This function or variable may be unsafe. Consider
using scanf_s instead. To disable deprecation, use ...

3. warning C4996: 'fopen' was declared deprecated.... : see declaration
of 'fopen' Message: 'This function or variable may be unsafe. Consider
using fopen_s instead. To disable deprecation, use
_CRT_SECURE_NO_DEPRECATE. See online help for details.'
How do I fix these problems? Sorry, but I'm not very experienced with C
programming.
Med venlig hilsen / Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
Feb 16 '06
185 17221
On Fri, 24 Feb 2006 20:45:57 +0000, Flash Gordon
<sp**@flash-gordon.me.uk> wrote:
If anyone thinks removing implicit int was a good thing because it adds
a requirement for using a function without a declaration in scope, there
Surely you don't mean 'requirement for'. Either requirement against,
or diagnostic for.
was a more direct way the same result could have been achieved. Adding a
requirement that there be a declaration in scope.

s/could have been/was/
- David.Thompson1 at worldnet.att.net
Mar 3 '06 #151
Keith Thompson wrote:
Prior to the ANSI standard, strdup() was commonly part of the C
library, right?
Not in the base <string.h>.
Why did the C89 standard include gets() but not strdup()?
Because gets() was in the legacy library and strdup() wasn't.

Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.
If gets() had been dropped from the standard back in 1989,
would that have been a bad thing; would you have (or did you) argue
for including it?


Actually I argued against including it in the first place,
but now that it is part of the standardized interface I see
no benefit and some harm in its removal.
Mar 3 '06 #152
On 2006-03-03, Douglas A. Gwyn <DA****@null.net> wrote:
Keith Thompson wrote:
Prior to the ANSI standard, strdup() was commonly part of the C
library, right?


Not in the base <string.h>.
Why did the C89 standard include gets() but not strdup()?


Because gets() was in the legacy library and strdup() wasn't.

Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.
If gets() had been dropped from the standard back in 1989,
would that have been a bad thing; would you have (or did you) argue
for including it?


Actually I argued against including it in the first place,
but now that it is part of the standardized interface I see
no benefit and some harm in its removal.


what harm?
Mar 3 '06 #153
"Douglas A. Gwyn" <DA****@null.net> writes:
Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.


Is it really true that no standard function malloc(s) storage?
--

John Devereux
Mar 3 '06 #154
Richard Bos wrote:
"Wojtek Lerch" <Wo******@yahoo.ca> wrote:
Well, exactly. It can be used safely, if you do control the input to stdin.

Sure. But this involves bondage gear, a single-user computer that has
never been connected to any kind of network, and deleting the executable
immediately after the single run.


Hardly. Gets() has been used in a zillion contexts where it has
not overflowed the allotted buffer, so it must not require all
of what you describe. You probably have in mind a usage model
that does *not* include controlling the input to stdin, which is
a different context.
Mar 3 '06 #155
Francis Glassborow wrote:
... I get tired of the
number of books for novices that still use gets(). As long as it is in
the Standard authors will just argue that they are using the standard
library.
If we removed it tomorrow, not a single program would fail but we could
condemn those that continue to teach its use and they would have
absolutely no defence.


First, you cannot "remove it tomorrow"; it's currently required
for standards conformance, and gets() will continue to be provided
in standard libraries for the indefinite future, even if it
eventually is no longer allowed for conformance for it to be
declared in <stdio.h> (which is a change that much legacy gets()-
using code wouldn't notice, due to explicitly declaring gets()
directly).

Also, if those books (taking your word for it since I'm not
familiar with them) use gets(), they should use the opportunity
to teach about the general buffer overrun issue, which is easy
for a novice to run afoul of. Indeed, a function similar to
gets() could easily be dreamed up as a nice way to encapsulate
reading a text line, and if the issue is not appreciated the odds
are that the programmer will just recreate the same problem.

Finally, if those books are claiming that gets() is good practice
for general contexts (unconstrained stdin), then they already
have no good defense; the "defense" that the interface can be
found in some (non-safety oriented) standards document is already
not justification for using any function inappropriately.

Pedagogically, gets() is a good example to have around.
Mar 3 '06 #156
Rod Pemberton wrote:
... People who do care about it use safer functions.


Indeed, and they generally use their own support library.
The converse point is important also: Please who don't
exert sufficient care about gets() usage aren't likely
to produce safe code regardless of whether gets() exists.
Mar 3 '06 #157
John Devereux <jd******@THISdevereux.me.uk> writes:
"Douglas A. Gwyn" <DA****@null.net> writes:
Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.


Is it really true that no standard function malloc(s) storage?


Well, obviously malloc() does, and calloc() and realloc() effectively
do. Other than that, fopen() and other functions *could* malloc
storage behind the scenes, but not in any manner that's visible to a
calling program.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #158
On 2006-03-03, Douglas A. Gwyn <DA****@null.net> wrote:
Richard Bos wrote:
"Wojtek Lerch" <Wo******@yahoo.ca> wrote:
> Well, exactly. It can be used safely, if you do control the input to stdin.

Sure. But this involves bondage gear, a single-user computer that has
never been connected to any kind of network, and deleting the executable
immediately after the single run.


Hardly. Gets() has been used in a zillion contexts where it has
not overflowed the allotted buffer, so it must not require all
of what you describe. You probably have in mind a usage model
that does *not* include controlling the input to stdin, which is
a different context.


And how is the input controlled? Blind luck?
Mar 3 '06 #159
CBFalconer wrote:
Chris Torek wrote:
The function fpurge() erases any input or output buffered in the
given stream. For output streams this discards any unwritten
output. For input streams this discards any input read from the
underlying object but not yet obtained via getc(3); this
includes any text pushed back via ungetc.

Your version seems eminently useful, and offhand I see no reason
for it not to be implementable on all C systems. Not portably
implementable, however. Which, to me, is an excellent reason to
incorporate it in the standard.


It's not evident how useful it is in general, because details
of the buffering vary among platforms. For example, on some
systems multiple input or output lines might be buffered while
on others just one line at a time might be, depending on file
type etc. There are also multiple levels of buffering,
including kernel character queues, etc. and one needs to
specify whether or not unread/unwritten buffered data is
flushed at that level also. For a specific platform one can
handle all the details, but for general use it would be not
only a problem to specify adequately but also to use in a
portable manner.
Mar 3 '06 #160
Jordan Abel wrote:
And how is the input controlled? Blind luck?


No. How is an automobile's direction controlled? By blind luck?
Mar 3 '06 #161
Keith Thompson <ks***@mib.org> writes:
John Devereux <jd******@THISdevereux.me.uk> writes:
"Douglas A. Gwyn" <DA****@null.net> writes:
Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.


Is it really true that no standard function malloc(s) storage?


Well, obviously malloc() does, and calloc() and realloc() effectively
do. Other than that, fopen() and other functions *could* malloc
storage behind the scenes, but not in any manner that's visible to a
calling program.


I was thinking in particular about "big" functions like printf, and
embedded applications (where malloc / free use is often discouraged).

If it was guaranteed that standard functions did *not* use malloc
"behind the scenes", then this could be useful to know.

--

John Devereux
Mar 3 '06 #162
Douglas A. Gwyn wrote:
....
Hardly. Gets() has been used in a zillion contexts where it has
not overflowed the allotted buffer, ...
That just means that the developers were unlucky enough to have a bad
design's flaws fail to surface. It doesn't mean that the design wasn't
flawed.
... so it must not require all
of what you describe. You probably have in mind a usage model
that does *not* include controlling the input to stdin, which is
a different context.


Since I don't know of any portable way for a C program to control it's
own standard input, yes, I am using such a model. It's bad design for
the ability of a program to avoid udefined behavior rely upon that
program being used correctly. When used incorrectly, it should fail
gracefully; it should not have undefined behavior. Obviously, you have
less strict standards for the behavior of incorrectly-used programs.

It's OK for a program that's not intended to be portable, to use
non-portable methods to control it's own standard input, but I don't
think the existence of such methods on some platforms should have any
influence over whether or not gets() remains in the standard library.

Mar 3 '06 #163
John Devereux <jd******@THISdevereux.me.uk> writes:
Keith Thompson <ks***@mib.org> writes:
John Devereux <jd******@THISdevereux.me.uk> writes:
"Douglas A. Gwyn" <DA****@null.net> writes:

Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.

Is it really true that no standard function malloc(s) storage?


Well, obviously malloc() does, and calloc() and realloc() effectively
do. Other than that, fopen() and other functions *could* malloc
storage behind the scenes, but not in any manner that's visible to a
calling program.


I was thinking in particular about "big" functions like printf, and
embedded applications (where malloc / free use is often discouraged).

If it was guaranteed that standard functions did *not* use malloc
"behind the scenes", then this could be useful to know.


There's no such guarantee in the standard. Nothing other than
malloc(), calloc(), and realloc() returns a pointer that the program
should, or may, pass to free(), but other library functions are
allowed to use *alloc() and free() internally.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #164
Keith Thompson wrote:
John Devereux <jd******@THISdevereux.me.uk> writes:
"Douglas A. Gwyn" <DA****@null.net> writes:
Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.


Is it really true that no standard function malloc(s) storage?


Well, obviously malloc() does, and calloc() and realloc() effectively
do. Other than that, fopen() and other functions *could* malloc
storage behind the scenes, but not in any manner that's visible to a
calling program.


Many of the standard library functions contain wording that says that
other library functions must behave as-if they never call that
particular function. I can find no such wording for the malloc()
family.

On the other hand, I can't think of any portable method of detecting
whether or not malloc() was called by, for instance, printf().
Correspondingly, I can't think of any reason why it should matter.

Mar 3 '06 #165
John Devereux <jd******@THISdevereux.me.uk> writes:
Keith Thompson <ks***@mib.org> writes:
John Devereux <jd******@THISdevereux.me.uk> writes:
"Douglas A. Gwyn" <DA****@null.net> writes:

Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.

Is it really true that no standard function malloc(s) storage?


Well, obviously malloc() does, and calloc() and realloc() effectively
do. Other than that, fopen() and other functions *could* malloc
storage behind the scenes, but not in any manner that's visible to a
calling program.


I was thinking in particular about "big" functions like printf, and
embedded applications (where malloc / free use is often discouraged).

If it was guaranteed that standard functions did *not* use malloc
"behind the scenes", then this could be useful to know.


No such guarantee may be made. Doug's point, I think, was that none of
the other standard functions /require/ allocating storage.

But, as a quality-of-implementation issue, I'd be fairly miffed if
printf() did a buncha allocating, as it's clearly unnecessary. Also,
nothing specifically allows printf() to fail due to allocation
problems, and therefore it is not allowed (in that, it is not one of
the explicitly listed exceptions for the requirement that it behave as
described by the standard, every time).
Mar 3 '06 #166
On 2006-03-03, Douglas A. Gwyn <DA****@null.net> wrote:
Jordan Abel wrote:
And how is the input controlled? Blind luck?


No. How is an automobile's direction controlled? By blind luck?


"Steering an automobile into a concrete wall will cause a crash" is
acceptable and widely understood by drivers. I'd dispute both that
"entering more than _x_ characters at _y_ prompt will cause a crash (or
other undefined behavior)" is acceptable and that it's typically
documented.
Mar 3 '06 #167
ku****@wizard.net writes:
Keith Thompson wrote:
John Devereux <jd******@THISdevereux.me.uk> writes:
> "Douglas A. Gwyn" <DA****@null.net> writes:
>
>> Some of us tried to get strdup() adopted for the standard,
>> but there was resistance primarily on the grounds that no other
>> standard function malloc()ed storage and the opposition didn't
>> want to start that as a design trend.
>
> Is it really true that no standard function malloc(s) storage?


Well, obviously malloc() does, and calloc() and realloc() effectively
do. Other than that, fopen() and other functions *could* malloc
storage behind the scenes, but not in any manner that's visible to a
calling program.


Many of the standard library functions contain wording that says that
other library functions must behave as-if they never call that
particular function. I can find no such wording for the malloc()
family.


Even if there were such wording, an implementation could easily get
around it by providing a lower-level __malloc() function. malloc()
itself could just call __malloc(); other library functions couldn't
call malloc(), but they could call __malloc(). One could argue either
way on the question of whether this meets the "as-if" requirement.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #168
On 2006-03-03, Keith Thompson <ks***@mib.org> wrote:
ku****@wizard.net writes:
Keith Thompson wrote:
John Devereux <jd******@THISdevereux.me.uk> writes:
> "Douglas A. Gwyn" <DA****@null.net> writes:
>
>> Some of us tried to get strdup() adopted for the standard,
>> but there was resistance primarily on the grounds that no other
>> standard function malloc()ed storage and the opposition didn't
>> want to start that as a design trend.
>
> Is it really true that no standard function malloc(s) storage?

Well, obviously malloc() does, and calloc() and realloc() effectively
do. Other than that, fopen() and other functions *could* malloc
storage behind the scenes, but not in any manner that's visible to a
calling program.


Many of the standard library functions contain wording that says that
other library functions must behave as-if they never call that
particular function. I can find no such wording for the malloc()
family.


Even if there were such wording, an implementation could easily get
around it by providing a lower-level __malloc() function. malloc()
itself could just call __malloc(); other library functions couldn't
call malloc(), but they could call __malloc(). One could argue either
way on the question of whether this meets the "as-if" requirement.


Standard library functions _are_ forbidden from calling the rand()
function, and as far as I know the reason for this leads to the
conclusion that they're not permitted to do anything that messes with
rand()'s internal state. However, this can be easily detected in a
conforming program, whereas I'm at a loss to figure out how a conforming
program could detect memory allocation.
Mar 3 '06 #169
Keith Thompson said:
John Devereux <jd******@THISdevereux.me.uk> writes:

Is it really true that no standard function malloc(s) storage?


Well, obviously malloc() does,


You mean malloc calls malloc? ;-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 3 '06 #170
Richard Heathfield <in*****@invalid.invalid> writes:
Keith Thompson said:
John Devereux <jd******@THISdevereux.me.uk> writes:
Is it really true that no standard function malloc(s) storage?


Well, obviously malloc() does,


You mean malloc calls malloc? ;-)


As a verb, "malloc()" means "whatever malloc does". malloc presumably
doesn't call malloc (though I suppose it could), but it does malloc().

That's my story, and I'm sticking to it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #171
On 3 Mar 2006 22:00:38 GMT, in comp.lang.c , Jordan Abel
<ra*******@gmail.com> wrote:
On 2006-03-03, Douglas A. Gwyn <DA****@null.net> wrote:
Jordan Abel wrote:
And how is the input controlled? Blind luck?


No. How is an automobile's direction controlled? By blind luck?


"Steering an automobile into a concrete wall will cause a crash" is
acceptable and widely understood by drivers. I'd dispute both that
"entering more than _x_ characters at _y_ prompt will cause a crash (or
other undefined behavior)" is acceptable and that it's typically
documented.


Nowhere in my /automobile/ documentation does it say "do not steer
this vehicle into a wall". I was taught this when I learned to drive.
Nowhere in my /compiler/ documentation does it say "do not overflow
arrays". I was taught this when I learned to programme.

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mar 3 '06 #172
On 2006-03-03, Mark McIntyre <ma**********@spamcop.net> wrote:
On 3 Mar 2006 22:00:38 GMT, in comp.lang.c , Jordan Abel
<ra*******@gmail.com> wrote:
On 2006-03-03, Douglas A. Gwyn <DA****@null.net> wrote:
Jordan Abel wrote:
And how is the input controlled? Blind luck?

No. How is an automobile's direction controlled? By blind luck?


"Steering an automobile into a concrete wall will cause a crash" is
acceptable and widely understood by drivers. I'd dispute both that
"entering more than _x_ characters at _y_ prompt will cause a crash (or
other undefined behavior)" is acceptable and that it's typically
documented.


Nowhere in my /automobile/ documentation does it say "do not steer
this vehicle into a wall". I was taught this when I learned to drive.
Nowhere in my /compiler/ documentation does it say "do not overflow
arrays". I was taught this when I learned to programme.


Exactly. And you shouldn't assume that your users, even if they do know
how to program, know there is an array overflow lurking. Even if you
tell them, that's not an acceptable "feature" for a program to have.
Mar 4 '06 #173
On Fri, 03 Mar 2006 18:34:08 +0000 in comp.std.c, John Devereux
<jd******@THISdevereux.me.uk> wrote:
"Douglas A. Gwyn" <DA****@null.net> writes:
Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.


Is it really true that no standard function malloc(s) storage?


Probably, "no standard function shall call {c,m,re}alloc or free".
OTOH fopen, fclose, setvbuf, and some others may dynamically
(de-)allocate memory.

--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada

Br**********@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
fake address use address above to reply
Mar 4 '06 #174
"Douglas A. Gwyn" wrote:
Jordan Abel wrote:
And how is the input controlled? Blind luck?


No. How is an automobile's direction controlled? By blind luck?


Yes, as is made supremely evident by observing traffic anywhere in
the world for significant length of time.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
Mar 4 '06 #175
"Douglas A. Gwyn" wrote:
CBFalconer wrote:
Chris Torek wrote:

The function fpurge() erases any input or output buffered in the
given stream. For output streams this discards any unwritten
output. For input streams this discards any input read from the
underlying object but not yet obtained via getc(3); this
includes any text pushed back via ungetc.


Your version seems eminently useful, and offhand I see no reason
for it not to be implementable on all C systems. Not portably
implementable, however. Which, to me, is an excellent reason to
incorporate it in the standard.


It's not evident how useful it is in general, because details
of the buffering vary among platforms. For example, on some
systems multiple input or output lines might be buffered while
on others just one line at a time might be, depending on file
type etc. There are also multiple levels of buffering,
including kernel character queues, etc. and one needs to
specify whether or not unread/unwritten buffered data is
flushed at that level also. For a specific platform one can
handle all the details, but for general use it would be not
only a problem to specify adequately but also to use in a
portable manner.


But that is precisely the point. Only the system designer knows
how to make the function work on his system. I should think of it
as a means to guarantee that any future input occured after the
call to fpurge. It puts the input system in a known state and
avoids having to keep track of line ending absorption.

With it fgets would be useful. Just specify the min. length of
line you want to consider, and use fpurge to eliminate the rest.
If there is no rest, fpurge does nothing.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
Mar 4 '06 #176
In article <44***************@null.net>, Douglas A. Gwyn
<DA****@null.net> writes
Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.


You mean like calloc and realloc:-) Of course those functions might be
implemented in a free standing way but conceptually they acquire memory
from the heap. The same applies to strdup (which might also be
implemented directly rather than by using malloc).

C has a family of functions that acquire memory from the heap and a
function free() that releases such memory. In what way does strdup() not
qualify to be a member? Indeed had it been we would not have the
resource leakage brought about by naive programmers who do not realise
that third party supplied functions such as strdup need a corresponding
call to free().
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
Mar 4 '06 #177
In article <44***************@null.net>, Douglas A. Gwyn
<DA****@null.net> writes
Pedagogically, gets() is a good example to have around.


If the desired lesson is that using the Standard Library is dangerous:-)
When a student uses gets() it is much harder to persuade them that even
with, for example, the commonly used char buffer[BUFSIZE] when 19 out of
every 20 introductory books use it and it is in the Standard Library.
You know not to use it and so does everyone here yet it is in wide use
in the real world. The first step is to remove the endorsement of the C
Standard. And note that we could do so if we had the will because we do
have the power to issue a normative correction to the Standard even if
that would be very rare. Actually removing gets() would be one of the
few places that using such power could be justified and the resulting
exposure in the media might get the message home more effectively than
anything else we have available.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
Mar 4 '06 #178
In article <sd********************************@4ax.com>, Mark McIntyre
<ma**********@spamcop.net> writes
Nowhere in my /automobile/ documentation does it say "do not steer
this vehicle into a wall". I was taught this when I learned to drive.
Nowhere in my /compiler/ documentation does it say "do not overflow
arrays". I was taught this when I learned to programme.


But the former is common sense (though with the litigious behaviour that
is common these days perhaps there should be a warning in the
documentation for vehicles :-) The latter is very far from obvious, has
to be taught and manifestly is usually (certainly considering the range
of academic authors who use it in their books) not taught.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
Mar 4 '06 #179
On Sat, 4 Mar 2006 13:00:56 +0000, in comp.lang.c , Francis Glassborow
<fr*****@robinton.demon.co.uk> wrote:
In article <sd********************************@4ax.com>, Mark McIntyre
<ma**********@spamcop.net> writes
Nowhere in my /automobile/ documentation does it say "do not steer
this vehicle into a wall". I was taught this when I learned to drive.
Nowhere in my /compiler/ documentation does it say "do not overflow
arrays". I was taught this when I learned to programme.


But the former is common sense


Oh, did someone say that there was a requirement not to teach obvious
stuff? Hmm, that must have escaped most of the establishment.

Well then, pick your example - don't overfeed your fish, don't walk
through deep rivers, don't cross thin ice, etc. These are all things
you can learn either by instruction or experience. Documentation is
unlikely to be useful because hey, who reads the instructions on your
fishfood?

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mar 4 '06 #180
On 2006-03-04, Mark McIntyre <ma**********@spamcop.net> wrote:
On Sat, 4 Mar 2006 13:00:56 +0000, in comp.lang.c , Francis Glassborow
<fr*****@robinton.demon.co.uk> wrote:
In article <sd********************************@4ax.com>, Mark McIntyre
<ma**********@spamcop.net> writes
Nowhere in my /automobile/ documentation does it say "do not steer
this vehicle into a wall". I was taught this when I learned to drive.
Nowhere in my /compiler/ documentation does it say "do not overflow
arrays". I was taught this when I learned to programme.


But the former is common sense


Oh, did someone say that there was a requirement not to teach obvious
stuff? Hmm, that must have escaped most of the establishment.


There's still the fact that everyone learns it, while no non-programmer
is told about buffer overflows and even users of your program who are
competent in programming won't know that your program contains a buffer
overflow flaw unless they actually look.
Mar 4 '06 #181
Brian Inglis wrote:
On Fri, 03 Mar 2006 18:34:08 +0000 in comp.std.c, John Devereux
<jd******@THISdevereux.me.uk> wrote:

"Douglas A. Gwyn" <DA****@null.net> writes:

Some of us tried to get strdup() adopted for the standard,
but there was resistance primarily on the grounds that no other
standard function malloc()ed storage and the opposition didn't
want to start that as a design trend.


Is it really true that no standard function malloc(s) storage?

Probably, "no standard function shall call {c,m,re}alloc or free".
OTOH fopen, fclose, setvbuf, and some others may dynamically
(de-)allocate memory.

Do you mean to be confusing?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Mar 4 '06 #182
Douglas A. Gwyn wrote
(in article <43**************@null.net>):
CBFalconer wrote:
The target should be new code. One urgent and
overdue step is the deprecation of gets.
New code doesn't need to use gets.


But it does. At a scary rate. It is apparent that far too many
of those learning C today are being taught by dinosaurs.
Perhaps a surprise inspection of C instructors world-wide needs
to be held next Tuesday, and anyone that isn't familiar with the
gets() problems would be killed on site. But, I digress...
Recall that gets was
specified in the standard simply because it was a widely
used piece of the base library. Almost any function can
be abused, but that doesn't mean they all need to be
deprecated.


But gets() does. Not only can it be abused, it's almost
impossible to use it in a way that isn't problematic.

Perhaps the reference implementation of gets() -- if for some
unfathomable reason it is not deprecated -- should be the normal
broken, crap behavior, along with the added bonus of a message
output to stderr (if available) along the lines of:

** WARNING: The programmer that wrote this code is lazy,
** poorly trained, and in dire need of a 2x4 up the side of the
** head. If you continue to use this program, despite this
** issue, you need to have your head examined as well.
** Suitable replacement candidates can be recruited from
** comp.lang.c or comp.std.c. Now back to your broken program
** in progress...
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Mar 4 '06 #183
Richard G. Riley wrote
(in article <46************@individual.net>):
On 2006-02-23, pete <pf*****@mindspring.com> wrote:

What do you mean about strtok?
If you call strtok with two string pointers as arguments,
you have defined behavior. Teh Enb.

I was referring more to the fact its buggy in a reentrant system
since its internal databuffer is static.


That's not a bug, it's a failure of the programmer to understand
what he/she is doing. Lots of functions are not reentrant.
That does not mean they are buggy. You could make a case for a
warning in the man pages or other documentation for the
terminally thick, but that's a different issue.
But anyway, regardless, why the pressure on the other function
[ed: gets()] which is undoubtedly in hundreds of thousands of
lines of legacy code?


Because it is in hundreds of thousands of lines of legacy code.

Seriously.

If you don't understand the problems with gets() at this point,
you are in dire need of a clue. Google for gets buffer overrun
and start reading.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Mar 4 '06 #184
Douglas A. Gwyn wrote:
Jordan Abel wrote:
And how is the input controlled? Blind luck?


No. How is an automobile's direction controlled? By blind luck?


I would say that using gets() for input can better be compared to using
an accelerometer that has too small a range to detect a crash at 120
km/h. "Warning: At speeds exceeding 60 km/h, the airbags may fail."

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
Mar 6 '06 #185
in comp.lang.c i read:
But that is precisely the point. Only the system designer knows
how to make the function work on his system. I should think of it
as a means to guarantee that any future input occured after the
call to fpurge. It puts the input system in a known state and
avoids having to keep track of line ending absorption.


perhaps. it certainly would make some people think that such a state could
be reached, when in fact there are aspects that can never be covered. time
is a harsh mistress -- consider bytes still in flight and thus, perhaps,
partially received sequences.

--
a signature
Apr 3 '06 #186

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1515
by: Juggernaut | last post by:
Hi I was trying to write a script to replace some text inside some tags. Lets say I had <tag stuff=stuff><tag stuff=otherstuff><another> I wanted it to find all the <tag and remove them. So...
11
2320
by: Savas Ates | last post by:
CREATE PROCEDURE st_deneme @userid numeric (18) ,@result numeric (18) output AS select * from users return "10" GO **************************** <!--METADATA TYPE="typelib" NAME="Microsoft...
7
1647
by: Wen | last post by:
Hi everyone, ..After my first lesson, I have to create a asp page with: ..asp tag for time ..client script that runs at the server for date ..client script that runs at client and shows a...
0
364
by: Daniel | last post by:
how to make sure a xsl document has valid xsl syntax? i tried loading it into an xml document but that doesnt show syntax errors inside attributes such as "foo/bar" vs "bar\foo"
13
1578
by: nigel.t | last post by:
Using linux <?php exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$returnval); ?> or perhaps try it on your system and tell me if it does/doesnt and what your linux is? I've also tried
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.