The C FAQ

J

jacob navia

This document shows its age. I remember complaining here some years ago
about this MSDOS questions but they are still there:

19.17c How can I suppress the dreaded MS-DOS ``Abort, Retry, Ignore?''
message?

19.23 How can I allocate arrays or structures bigger than 64K?

19.24 What does the error message ``DGROUP data allocation exceeds 64K''
mean, and what can I do about it? I thought that using large model meant
that I could use more than 64K of data!

19.29 How do I get an accurate error status return from system on MS-DOS?

19.40b How do I... Use BIOS calls? Write ISR's? Create TSR's?

19.40d What are ``near'' and ``far'' pointers?

MSDOS died some 20 years ago (more or less).

CAN WE GET RID OF THAT?

There is no word about windows/unix/Mac OS X and systems used TODAY...

And there are things like:

7.17 I've got 8 meg of memory in my PC. Why can I only seem to malloc
640K or so?

Theren't a single PC today that is shipped with less than 512K...
most are shipped with 1-4GB, my machine has 12GB. And YES: MSDOS is
dead.


Other answers are just wrong:


11.8: I don't understand why I can't use const values in initializers
and array dimensions, as in

const int n = 5;
int a[n];

The answer given is:

The const qualifier really means ``read-only''; an object so qualified
is a run-time object which cannot (normally) be assigned to. The value
of a const-qualified object is therefore not a constant expression in
the full sense of the term, and cannot be used for array dimensions,
case labels, and the like. (C is unlike C++ in this regard.) When you
need a true compile-time constant, use a preprocessor #define (or
perhaps an enum).


This is plain wrong. You CAN do this within a function in standard C.
That should be mentioned there. ANd NOT only with const but with any
variable of integer type.

Another is:
2.6: I came across some code that declared a structure like this:

struct name {
int namelen;
char namestr[1];
};

and then did some tricky allocation to make the namestr array act like
it had several elements, with the number recorded by namelen. How does
this work? Is it legal or portable?

The answer starts with:

It's not clear if it's legal or portable, but it is rather popular.

And after a page of ramblings comes to:
C99 introduces the concept of a flexible array member, which allows the
size of an array to be omitted if it is the last member in a structure,
thus providing a well-defined solution.

That should be at the beginning, and the whole answer must be changed
to reflect the fact that standard C accepts this!

jacob
 
S

Seebs

MSDOS died some 20 years ago (more or less).

CAN WE GET RID OF THAT?

The most recent edition of Schildt's "C: The Complete Reference" still
has near and far pointers. And, whether we like it or not, there's still
code out there that has those references in it, and someone might need
to port it.
This is plain wrong. You CAN do this within a function in standard C.
That should be mentioned there. ANd NOT only with const but with any
variable of integer type.

It's not accurate for C99 or GNU C. The problem is that the question used
"array size" as an example of something which implicitly needed an "integer
constant", but of course, it's not anymore.
That should be at the beginning, and the whole answer must be changed
to reflect the fact that standard C accepts this!

"must" seems a little strong.

I agree that it would be great if Steve updated the FAQ. But, since I'm not
paying him to do it, I don't feel like I'm in a great position to impose
conditions or requirements.

-s
 
A

Alan Curry

|> MSDOS died some 20 years ago (more or less).

Hmm... I had to get PeeCee with DOS to play DOOM (now widely ported, but the
DOS version came out first, and the other ports were missing features for a
long time). That was less than 17 years ago. And not exactly an obscure
application running on legacy hardware either.

Of course that machine did come preinstalled with a "win" line in its
autoexec.bat which in hindsight is recognizable as the beginning of the end
of DOS.

|>
|> CAN WE GET RID OF THAT?
|
|The most recent edition of Schildt's "C: The Complete Reference" still
|has near and far pointers. And, whether we like it or not, there's still
|code out there that has those references in it, and someone might need
|to port it.

But the F in FAQ stands for something, and it's not "all questions ever".
Killing off the ones that have become infrequent would make the list shorter,
and a shorter list will be read by more people.

|
|> This is plain wrong. You CAN do this within a function in standard C.
|> That should be mentioned there. ANd NOT only with const but with any
|> variable of integer type.
|
|It's not accurate for C99 or GNU C. The problem is that the question used
|"array size" as an example of something which implicitly needed an "integer
|constant", but of course, it's not anymore.

It still works if you assume it's outside of a function. Inside a function,
change it to a case label in a switch to make the same point.
 
K

Keith Thompson

jacob navia said:
This document shows its age. I remember complaining here some years ago
about this MSDOS questions but they are still there:

19.17c How can I suppress the dreaded MS-DOS ``Abort, Retry, Ignore?''
message? [...]
MSDOS died some 20 years ago (more or less).

CAN WE GET RID OF THAT?

Is MSDOS really completely dead? I know it's not used much anymore,
and I agree that it probably doesn't deserve as much mention as it
gets in the FAQ, but I think it's still used in some niche
applications.
There is no word about windows/unix/Mac OS X and systems used TODAY...

And there are things like:

7.17 I've got 8 meg of memory in my PC. Why can I only seem to malloc
640K or so?

Theren't a single PC today that is shipped with less than 512K...

You mean 512M, don't you?
most are shipped with 1-4GB, my machine has 12GB. And YES: MSDOS is
dead.

Yes, the numbers are dated, but the principle is unchanged. The
question and answer could both be improved by making them more
generic.
Other answers are just wrong:


11.8: I don't understand why I can't use const values in initializers
and array dimensions, as in

const int n = 5;
int a[n];

The answer given is:

The const qualifier really means ``read-only''; an object so qualified
is a run-time object which cannot (normally) be assigned to. The value
of a const-qualified object is therefore not a constant expression in
the full sense of the term, and cannot be used for array dimensions,
case labels, and the like. (C is unlike C++ in this regard.) When you
need a true compile-time constant, use a preprocessor #define (or
perhaps an enum).


This is plain wrong. You CAN do this within a function in standard C.
That should be mentioned there. ANd NOT only with const but with any
variable of integer type.

Yes, in C99, which not all compilers fully support. (Yes, jacob, we
know ...)

I agree that that answer should be updated. Note, however, that n is
*still* not a constant expression. C99 allows it to be used as an
array dimension, but it still can't be used in case labels and a few
other contexts. And depending on the cleverness of the compiler, there
might be a difference between
const int n = 5;
int a[n]; /* This is a VLA */
and
enum { n = 5 };
int a[n]; /* This is not a VLA */

Even if C99 were universally available, I'd still tend to prefer the
latter, just to avoid runnng into any problems with the differences
between VLAs and non-VLAs.
Another is:
2.6: I came across some code that declared a structure like this:

struct name {
int namelen;
char namestr[1];
};

and then did some tricky allocation to make the namestr array act like
it had several elements, with the number recorded by namelen. How does
this work? Is it legal or portable?

The answer starts with:

It's not clear if it's legal or portable, but it is rather popular.

Which is still true. There's still plenty of code that uses the
struct hack, even though it's not needed in C99. The question begins,
"I came across some code ..."; this is something that programmers are
still likely to run into. (If nothing else, that answer would be
improved by mentioning the phrase "struct hack".)
And after a page of ramblings comes to:
C99 introduces the concept of a flexible array member, which allows
the size of an array to be omitted if it is the last member in a
structure, thus providing a well-defined solution.

That should be at the beginning, and the whole answer must be changed
to reflect the fact that standard C accepts this!

I agree that the FAQ needs some updating. It was last updated in
2005, and that wasn't a complete update. But keep in mind that
it's basically a one-man volunteer effort.

I don't pretend to speak for Steve Summit, but perhaps he'd be
interested in an project where we provide updated answers for
his approval. We've always been free to provide input by e-mail,
but that tends to be rather haphazard.
 
E

Eric Sosman

This document shows its age. I remember complaining here [...]

Why complain here? Why not complain to Steve Summit, the
author of the FAQ and the holder of its copyright? His contact
information is easily found in the -- wait for it -- FAQ ...
 
S

Stephen Sprunk

MSDOS died some 20 years ago (more or less).

No, MS DOS stopped shipping less than 10 years ago; it was still
underneath the hood of MS Windows 3.x, 95, 98, and ME.
CAN WE GET RID OF THAT?

Not until MS DOS--and every bit of source code that _assumes_ it is
running on MS DOS even if it's actually under emulation--is completely
eradicated, and I suspect that'll be another few decades.

Every now and then, I find a useful piece of software for MS DOS that
needs to be ported to something modern; understanding "near" and "far"
pointers (and some other MS DOS oddities) is still useful. Even for
those of us who were there, a refresher is still handy.

OTOH, given this group's topicality Nazis, one could easily argue that
any references to _any_ particular OS should be stricken from the FAQ.
There is no word about windows/unix/Mac OS X and systems used TODAY...

Indeed, and that could use some work, along with many other ares. If
you want it improved, I'm sure the maintainer would appreciate suggestions.
And there are things like:

7.17 I've got 8 meg of memory in my PC. Why can I only seem to malloc
640K or so?

Theren't a single PC today that is shipped with less than 512K...
most are shipped with 1-4GB, my machine has 12GB. And YES: MSDOS is
dead.

True, though there are plenty of folks working on embedded systems that
have even less memory than that; they're just not PCs.
Other answers are just wrong:

11.8: I don't understand why I can't use const values in initializers
and array dimensions, as in

const int n = 5;
int a[n];

The answer given is:

The const qualifier really means ``read-only''; an object so qualified
is a run-time object which cannot (normally) be assigned to. The value
of a const-qualified object is therefore not a constant expression in
the full sense of the term, and cannot be used for array dimensions,
case labels, and the like. (C is unlike C++ in this regard.) When you
need a true compile-time constant, use a preprocessor #define (or
perhaps an enum).


This is plain wrong. You CAN do this within a function in standard C.
That should be mentioned there. ANd NOT only with const but with any
variable of integer type.

True, it's been a poor example since C99 added VLAs. Better would be a
switch/case statement, where a "const int" still can't be used.
Another is:
2.6: I came across some code that declared a structure like this:

struct name {
int namelen;
char namestr[1];
};

and then did some tricky allocation to make the namestr array act like
it had several elements, with the number recorded by namelen. How does
this work? Is it legal or portable?

The answer starts with:

It's not clear if it's legal or portable, but it is rather popular.

And after a page of ramblings comes to:
C99 introduces the concept of a flexible array member, which allows the
size of an array to be omitted if it is the last member in a structure,
thus providing a well-defined solution.

That should be at the beginning, and the whole answer must be changed
to reflect the fact that standard C accepts this!

Indeed. In general, as with the comment directly above, it appears that
the FAQ has not been updated to reflect the changes from C99 or, at
minimum, documented to say the answers only refer to C89.

S
 
K

Kaz Kylheku

The most recent edition of Schildt's "C: The Complete Reference" still
has near and far pointers. And, whether we like it or not, there's still
code out there that has those references in it, and someone might need
to port it.

The F in FAQ stands for something, though.
 
J

jacob navia

Richard Heathfield a écrit :
jacob navia said:
This document shows its age. I remember complaining here some years ago
about this MSDOS questions but they are still there:

19.17c How can I suppress the dreaded MS-DOS ``Abort, Retry, Ignore?''
message? [...]
MSDOS died some 20 years ago (more or less).

CAN WE GET RID OF THAT?

I am personally aware of several extant MS-DOS installations, on several
separate sites. (In fact, I have one right here, about fifteen feet
away.)

I would never doubt that. It is just near your 10 year old version of
gcc that you refuse to upgrade, and near a version of the C89 standard
that you also refuse to upgrade.

And behind that MSDOS system is a song of Jethro Tull:

"Living in the past".

Ahhh those were the times my friend. They will never come again.
 
J

jacob navia

Stephen Sprunk a écrit :
No, MS DOS stopped shipping less than 10 years ago; it was still
underneath the hood of MS Windows 3.x, 95, 98, and ME.

The Win32 API of 95 is still there. So what? You would tell me that
MSDOS is still shipping today or what?

We are speaking of the FAQ of 2010, not the FAQ of 2000 or 1995. The
"F" means FREQUENT and I do not see much people around developing
ìn MSDOS. I could (maybe) understand if there were questions concerning
Unix development, or windows questions but MSDOS?
 
K

Kenny McCormack

Stephen Sprunk a écrit :

The Win32 API of 95 is still there. So what? You would tell me that
MSDOS is still shipping today or what?

We are speaking of the FAQ of 2010, not the FAQ of 2000 or 1995. The
"F" means FREQUENT and I do not see much people around developing
ìn MSDOS. I could (maybe) understand if there were questions concerning
Unix development, or windows questions but MSDOS?

Just to argue the other side of this - let's remember that this is C
we're talking about here. An old-fashioned language that served us
well, but is, itself, basically obsolete. This is not to say that it
isn't still used or anything like that - but the fact is that very
little new development, on current/new OSes and platforms, is done in C.
Even C++ is considered "old" by most people these days.

Further, let's stipulate that both DOS and Unix are also considered
"old". Again, this doesn't mean that they aren't both in use and even
developed for, in various niche application domains.

So, what this all leads to is that it makes sense for the C FAQ to
contain a lot of content about DOS and Unix, since a lot of what makes C
what it is (warts and all) is tied to those OSes.
 
S

santosh

jacob said:
This document shows its age. I remember complaining here some years ago
about this MSDOS questions but they are still there:

MSDOS died some 20 years ago (more or less).

Nope. MS-DOS is still around, albeit as a lurker beneath WIndows. Yes,
huge numbers of people still use Windows 98/ME/2000/XP, all of which
provided DOS mode/prompt. I don't know about Vista and 7, but while
Vista died in infancy, 7 is yet to be widely adopted. Reluctance to
change a working system and learn new interfaces, and cost of
migrating are some important factors for why these "legacy" systems
are still widely used. Much of the same reasoning applies to why Turbo
C is still being widely used for teaching introductory C.

But I haven't seen a single "pure" MS-DOS installation since atleast a
decade.

But the pertinent question is not if MS-DOS is dead or not, but how
much C programming is still being done under DOS or DOS mode. As I
said above, many introductory C classes still use the Turbo C/DOS
prompt combine due to reasons given above. Some popularly used C
"textbooks" still make heavy references to, and contain instructions
for, DOS, making the new student think he must start with Turbo C/DOS.

Other than this I guess that DOS programming is still being actively
done only by DOS enthusiasts (of which there're still very many), and
perhaps in certain embedded areas.

So I guess it'd be cleaner if the DOS FAQs were moved into a separate
"DOS" section of the FAQ. Though I wouldn't like to see them removed
altogether, having them all collected under a single link would make
the rest of FAQ cleaner and more up-to-date seeming for the rest of
us.

<snip>
 
M

Mark Hobley

jacob navia said:
The Win32 API of 95 is still there. So what? You would tell me that
MSDOS is still shipping today or what?

Not MSDOS, but you can get freedos. (I run dos applications in dosemu here).

Mark.
 
A

Andrew Poelstra

Stephen Sprunk a écrit :

The Win32 API of 95 is still there. So what? You would tell me that
MSDOS is still shipping today or what?

We are speaking of the FAQ of 2010, not the FAQ of 2000 or 1995. The
"F" means FREQUENT and I do not see much people around developing
ìn MSDOS. I could (maybe) understand if there were questions concerning
Unix development, or windows questions but MSDOS?

I second this. MS-DOS has terribly limited networking support,
almost no support for modern filesystems, primitive threading
and IIRC, no memory protection. (Actually, the DOS functions
were so slow that you /had/ to use MMIO directly to draw graphics
at any decent speed.)

In any case, I do not believe that the memory limitations
discussed in the FAQ are at all frequently met. In fact, I
doubt that most C programmers encounter /any/ memory limits
on desktop PC's anymore. Certainly not when they're learning
and need a FAQ.
 
F

Flash Gordon

jacob said:
Richard Heathfield a écrit :
This document shows its age. I remember complaining here some years ago
about this MSDOS questions but they are still there:

19.17c How can I suppress the dreaded MS-DOS ``Abort, Retry, Ignore?''
message?
[...]
MSDOS died some 20 years ago (more or less).

CAN WE GET RID OF THAT?

I am personally aware of several extant MS-DOS installations, on
several separate sites. (In fact, I have one right here, about fifteen
feet away.)

I would never doubt that. It is just near your 10 year old version of
gcc that you refuse to upgrade, and near a version of the C89 standard
that you also refuse to upgrade.

You really should do a BIOS update on your PC one day... the last time I
did, within the last couple of years, it involved booting to DOS using
an image provided by the computer vendor.
And behind that MSDOS system is a song of Jethro Tull:

"Living in the past".

Ahhh those were the times my friend. They will never come again.

The past isn't as dead as you think.

Although I happen to agree that a lot of mention of DOS isn't really
needed in the FAQ these days.
 
F

Flash Gordon

santosh said:
Nope. MS-DOS is still around, albeit as a lurker beneath WIndows. Yes,
huge numbers of people still use Windows 98/ME/2000/XP, all of which
provided DOS mode/prompt. I don't know about Vista and 7, but while

Ask in a Windows group. That DOS prompt has in 2000 and above is NOT
running MS DOS or anything like it.

Vista died in infancy, 7 is yet to be widely adopted. Reluctance to
change a working system and learn new interfaces, and cost of
migrating are some important factors for why these "legacy" systems
are still widely used. Much of the same reasoning applies to why Turbo
C is still being widely used for teaching introductory C.

Well, the courses should move on to something more recent, and although
DOS is still used, it is gradually disappearing.
But I haven't seen a single "pure" MS-DOS installation since atleast a
decade.

But the pertinent question is not if MS-DOS is dead or not, but how
much C programming is still being done under DOS or DOS mode. As I
said above, many introductory C classes still use the Turbo C/DOS
prompt combine due to reasons given above. Some popularly used C
"textbooks" still make heavy references to, and contain instructions
for, DOS, making the new student think he must start with Turbo C/DOS.

Any introductory courses using it need serious updating.
Other than this I guess that DOS programming is still being actively
done only by DOS enthusiasts (of which there're still very many), and
perhaps in certain embedded areas.

DOS has been dropping out of the embedded market for a long time. I
don't know how much (if at all) it is still used.
So I guess it'd be cleaner if the DOS FAQs were moved into a separate
"DOS" section of the FAQ. Though I wouldn't like to see them removed
altogether, having them all collected under a single link would make
the rest of FAQ cleaner and more up-to-date seeming for the rest of
us.

A lot of the stuff, if re-cast, could still be relevant.
 
F

Flash Gordon

Andrew Poelstra wrote:

In any case, I do not believe that the memory limitations
discussed in the FAQ are at all frequently met. In fact, I
doubt that most C programmers encounter /any/ memory limits
on desktop PC's anymore. Certainly not when they're learning
and need a FAQ.

The specific values mentioned in the FAQ may be no longer relevant, but
we *do* have learners posting code which attempts to allocate local
variable which are so large the allocation fails causing the program to
crash. So there *are* still limits, and learners *do* still hit them!

We also have had people post things similar to, "...but I've got 4GM of
RAM!" when this is pointed out.
 
N

Nick Keighley

jacob navia wrote:


Nope. MS-DOS is still around, albeit as a lurker beneath WIndows.

not really. There's a CLI that looks a lot like DOS but it isn't
really DOS
Yes,
huge numbers of people still use Windows 98/ME/2000/XP, all of which
provided DOS mode/prompt. I don't know about Vista and 7, but while
Vista died in infancy, 7 is yet to be widely adopted.

eek! I'm using Vista. Admittedly I'm the only person in the world who
*likes* Vista, but still... Vista still has DOS-like CLI.

I've heard it said that W7 is pretty much the Vista OS but with some
cleanup to the GUI. The security is supposed to be less intrusive (I
*like* intrusive)
 
A

Andrew Poelstra

not really. There's a CLI that looks a lot like DOS but it isn't
really DOS


eek! I'm using Vista. Admittedly I'm the only person in the world who
*likes* Vista, but still... Vista still has DOS-like CLI.

I've heard it said that W7 is pretty much the Vista OS but with some
cleanup to the GUI. The security is supposed to be less intrusive (I
*like* intrusive)

No, Win7 is a -lot- faster. It's prettier and easier to use and
all that, but there's clearly been a lot of work under the hood.
(Though, they still won't let you accept RDP connections with a
home version. Silly Microsoft, I guess I'll stick with Linux.)


Andrew
 
S

santosh

Flash said:
Ask in a Windows group. That DOS prompt has in 2000 and above is NOT
running MS DOS or anything like it.

Yes, but that is not pertinent to this discussion is it? The NT family
emulates the DOS interface, but they still provide it, allowing almost
all programs to work, that'd run on native DOS.

In effect, they do "provide" DOS right upto Vista, though my
understanding is that Windows 7 has finally dropped support for it.

So potentially, all users of versions of Windows up to XP (and I think
Vista too), *can* use DOS programs and do a subset of DOS programming,
which is a *huge* user base.
Well, the courses should move on to something more recent, and although
DOS is still used, it is gradually disappearing.


Any introductory courses using it need serious updating.

Well, to be fair, top of the notch places have moved on to using some
version of Visual C++ and gcc under Linux, but the seedier
establishments still use old installs of Windows 98/DOS combo and
Turbo C/C++, since, I guess, they prefer saving the money they'd
otherwise've to shell out for Windows and Visual Studio licenses.

But their numbers are dropping. DOS might completely disappear in
about 5-10 years, except for hobbyists and other peculiar instances.

A lot of the stuff, if re-cast, could still be relevant.

Yes, but since it's a volunteer effort by Mr. Summit, it'd be mean to
carp too much without actually lending a hand. It's still a very
useful resource, but it used to be periodically posted to clc. I
wonder why that has been discontinued. A weekly post of it might bring
it to the attention of newbies and lurkers more effectively than
mentioning it only in occasional replies.
 
R

Richard Tobin

Joe Wright said:
MSDOS and CP/M are still very much "now" to me.

MSDOS and CP/M seem older than they are because they were out of date
when they were designed.

-- Richard
 

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top