}}
@end ifclear
@end example
That's it! To build a program for DOS, say something like this:
@example
gcc-dos hello.c -o hello.exe
@end example
@node 0xfe+0x20, Struct size, Cross-DJGPP, Miscellany
@comment node-name, next, previous, up
@section GCC says ``garbage at end of number''
@cindex Garbage at end of number, GCC message
@pindex GCC says ``garbage at end of number''
@quest{There is a severe bug in GCC: it says ``garbage at end of
number'' for this line:}
@example
i = 0xfe+0x20;
@end example
@paragraph{}
@emph{Ain't it silly that such a great compiler would fail so miserably?}
@ans{} That's not a bug, that's a feature of the @emph{ANSI C language
definition.} By ANSI rules, the above expression is a single
@dfn{preprocessing token}, unless you place whitespace in front of the
plus sign. The reason for this seemingly counterintuitive feature is
the syntax of floating-point constants in which letters `e' and `E'
followed immediately by a sign signal a decimal exponent. You can use
the @samp{-traditional} compiler switch to turn this feature off
(together with a plethora of other ANSI features; see the GCC docs for
details).
@node Struct size, Struct packing, 0xfe+0x20, Miscellany
@comment node-name, next, previous, up
@section What should sizeof (struct xyzzy) return?
@cindex Size of a struct under DJGPP
@cindex Struct, size in bytes under DJGPP
@cindex Structure padding
@cindex Packing the structs
@cindex Reading structs from disk files
@cindex Reading an int from a binary file
@cindex struct reading from a disk file
@pindex sizeof, result when called on a structure
@quest{When I call @samp{sizeof} on a struct, I sometimes get values
which are larger than the sum of the sizes of the struct fields, whereas
in Borland C++ I always get the correct result. Is it a bug in GCC?}
@quest{I have a program that reads struct contents from a binary file.
It works OK when compiled with BC, but reads garbage when compiled with
DJGPP. This must be a bug in DJGPP, right?}
@ans{} No, it's not a bug. GCC generates 32-bit code, and in that mode,
there is a significant penalty (in terms of run-time performance) for
unaligned accesses, like accessing a 16-bit short which isn't aligned on
a word boundary, or accessing a 32-bit int which isn't aligned on a
dword boundary. To produce faster code, GCC pads struct fields so that
each field can be accessed without delays; this sometimes produces
struct size which is larger than the sum of the sizes of its fields. If
you need to minimize this padding (e.g., if your program uses large arrays
of such structs, where padding will waste a lot of memory), lay out your
structures so that the longer fields are before the shorter ones. For
example, let's say that you have a struct defined thus:
@example
struct my_struct @{
char name[7];
unsigned long offset;
double quality;
@};
@end example
To make such a struct use the least number of bytes, rearrange the
fields, like this:@footnote{Note that this still allows the struct to be
padded at the end, though.}
@example
struct my_struct @{
double quality;
unsigned long offset;
char name[7];
@};
@end example
If the layout of the structure cannot be changed (e.g., when it must
match some external specification, like a block of data returned by some
system call), you can use the @code{__attribute__((packed))} extension
of GCC (@extref{Type Attributes, the Gcc docs, gcc, GNU C/C++ Manual,
www.delorie.com/gnu/docs/gcc/gcc_83.html#SEC86}.) to prevent GCC from
padding the structure fields; this will make accesses to some of the
fields slower.
@paragraph{}
Beginning from version 2.7.0, GCC has a command-line option
@samp{-fpack-struct} which causes GCC to pack all members of all structs
together without any holes, just as if you used
@code{__attribute__((packed))} on every struct declaration in the
source file you compile with that switch. If you use this switch, be
sure that source files which you compile with it don't use @strong{any}
of the structures defined by library functions, or you will get some
fields garbled (because the library functions weren't compiled with that
switch).
@paragraph{}
The padding of struct fields should be considered when you read or
write struct content from or to a disk file. In general, this should
only be done if the file is read and written by the same program,
because the exact layout of the struct fields depends on some subtle
aspects of code generation and the compiler switches used, and these may
differ between programs, even if they were compiled by the same compiler
on the same system. If you do need this method, be aware of the struct
field padding and don't assume that the number of the file bytes that
the structure uses is equal to the sum of the fields' sizes, even if you
instructed the compiler to pack structs: GCC still can add some padding
after the last field. So always use @code{sizeof struct foo} to read
and write a structure.
@paragraph{}
Another problem with porting programs that read structs from binary
files is that the size of some data types might be different under
different compilers. Specifically, an @code{int} is 16-bit wide in most
DOS-based compilers, but in DJGPP it's 32-bit wide.
@paragraph{}
The best, most robust and portable way to read and write structs is
through a @code{char} buffer, which your code then uses to move the
contents into or out of the struct fields, one by one. This way, you
always know what you are doing and your program will not break down if
the padding rules change one day, or if you port it to another
OS/compiler.
@node Struct packing, Int 24h, Struct size, Miscellany
@comment node-name, next, previous, up
@section C++ doesn't pack structs!
@cindex Structure packing, C++ bug
@cindex Packed structs, C++ bug
@cindex C++ programs, problems with packed structs
@pindex GCC doesn't pack structs in C++ programs
@quest{When I use @code{struct ffblk} from the header @file{dir.h} in a
C++ program, I get garbage in some fields of the structure!}
@ans{} There is a known bug in GCC 2.7.2: the C++ compiler effectively
ignores the @code{__attribute__((packed))} directives, so the structures
end up being not packed. As a work-around, surround the declaration of
the structure that needs to be packed with @code{#pragma pack}, like
this:
@example
#ifdef __cplusplus
#pragma pack(1)
#endif
.
.
.
#ifdef __cplusplus
#pragma pack()
#endif
@end example
@node Int 24h, go32-v2, Struct packing, Miscellany
@comment node-name, next, previous, up
@section How to avoid ``Abort, Retry, Fail'' messages
@cindex Interrupt 24h handling
@cindex Int 24h crashes DJGPP programs
@cindex harderr function, emulating under DJGPP
@cindex Critical error handling in DJGPP
@cindex Program crashes because of Int 24h
@cindex Program crashes accessing empty floppy/CD-ROM drives
@pindex QDPMI crashes DJGPP programs when they cause Int 24h
@pindex CWSDPMI doesn't support hooking Int 24h
@quest{How do I write a program that accesses floppy and CD-ROM drives,
but avoids popping that ``Abort, Retry, Fail?'' message from DOS?}
@quest{Other DOS compilers supply a function named @code{harderr} or
@code{_harderr} to hook the critical-error interrupt 24h, but DJGPP
doesn't seem to have these...}
@ans{} Under DPMI, Int 24h is always hooked by the DPMI server, since
Int 24h is issued by the real-mode DOS code, and it is not possible to
terminate a DPMI client (like DJGPP program) from real mode, if you
press @kbd{A} in response to that prompt. The default handler under
most DPMI servers will just set @code{AL} register to 3 and @code{IRET},
thus silently failing the DOS call that triggered Int 24h. The DJGPP
startup code also hooks the protected-mode Int 24h with a handler that
fails the DOS call as described above. So in most circumstances you
won't see that DOS prompt at all; your program will just see a failed
DOS call.
@paragraph{}
However, some DPMI hosts (notably, QDPMI), will sometimes crash your
program if it generates Int 24h, for instance when you access an empty
floppy drive. In such cases, or when the default action of failing the
DOS call is not good enough, you will have to hook Int 24h with your
handler. This should be done in exactly the same manner as hooking
hardware interrupts (@pxref{Hardware interrupts, how to set an interrupt
handler}), because Int 24h is one of the few software interrupts that,
like all hardware interrupts, are always reflected to the protected-mode
handler first. Note that @code{CWSDPMI} currently doesn't support
hooking Int 24h; if you set an interrupt handler, it won't be called.
@paragraph{}
There are ways to avoid program crashes due to Int 24h (under those DPMI
hosts that exhibit this buggy behavior) other than to install a handler
for it. For instance, you can test if the floppy drive is empty with a
BIOS call before accessing it with DOS functions; there are also similar
ways to check if a CD-ROM drive is empty. The library function
@code{getmntent} (@extref{getmntent, getmntent, libc.inf, libc.a
reference, www.delorie.com/djgpp/doc/libc-2.00/libc_111.html#SEC111}.)
can be used to detect all the drives that can be safely accessed by DOS;
or you can borrow some of the internal functions used by
@code{getmntent} from the @ftp{library source distribution,
@SimTel{}/pub/simtelnet/gnu/djgpp/v2/djlsr@value{djgpp-version}.zip}.
@node go32-v2, DXE, Int 24h, Miscellany
@comment node-name, next, previous, up
@section What is that @file{go32-v2.exe} program?
@cindex Invoking v2 programs from v1.x programs
@cindex Spawning v2 programs from v1.x programs
@pindex go32-v2 usage
@quest{What is go32-v2 for?}
@ans{} The @code{go32-v2} program does the following:
@itemize @bullet{}
@item
With no command-line arguments, it prints the available physical and
virtual memory, much like @code{go32} did in v1.x.
@item
It can run unstubified v2 COFF images, like this:
@example
go32-v2 myprog
@end example
@item
If you rename it to @file{go32.exe} and put on your @code{PATH} before
the v1.x @file{go32.exe}, it can also run a v1 COFF images, by loading
the v1.x @code{go32} and letting it do the job. With this setup, you
can run v2 programs from v1.x programs, because the v1.x program will
load @code{go32-v2} (since it found it first on the PATH) which knows
how to run v2 images, instead the original @code{go32} which cannot.
@end itemize
@node DXE, LFN, go32-v2, Miscellany
@comment node-name, next, previous, up
@section What is DXE?
@cindex DXE description
@cindex DXE docs and examples
@quest{What is DXE?}
@quest{Can I make a DLL using the DXE support?}
@quest{Where can I find information or examples about writing/loading
the DXE files?}
@ans{} DXE is a limited facility to dynamically load code which is
rarely needed in DJGPP. An example is the floating-point emulator code
(@pxref{Emulation, the details of DJGPP FP emulator}) which is only used
on those few machines that lack an FPU. The DXE design is intentionally
limited to keep it as simple as possible, so that the code that loads a
DXE could be small (it's a few hundreds bytes). Because of this, there
are a number of limitations in the DXE mechanism that prevent using it
for full-fledged dynamic linking (i.e., a DLL). For instance, the DXE
module cannot access variables or functions in the main module.
Unloading a DXE is also not supported (but I'm told you can add this by
making simple changes in the C library).
@paragraph{}
The only place you can find some docs and examples of writing and using
a DXE is in the file @file{djtst@value{djgpp-version}.zip} in the
@ftp{DJGPP ``tests'' distribution,
@SimTel{}/pub/simtelnet/gnu/djgpp/v2/djtst@value{djgpp-version}.zip}.
The example there is @emph{exceedingly} simplistic, but then so is the
entire DXE mechanism@dots{}
@node LFN, Missing separator, DXE, Miscellany
@comment node-name, next, previous, up
@section Long Filenames Don't Work!
@cindex LFN problems
@cindex long filename support, bugs
@quest{I cannot make Info find some of its files under Win95...}
@quest{Why does Make behave as if some of the files were not there?}
@ans{} Are you running DJGPP under Win95 with long filename support
enabled (LFN=y in the environment)? If so, set LFN=n from the DOS
prompt and try again. If the problems go away, they are probably due to
known bugs in some DJGPP programs wrt the LFN support. Make and Info
are two programs which are known to reveal these bugs. Before you
decide that you are a victim of these bugs, though, make sure that all
the files that your programs need to access have been renamed to their
long names. For example, if Make needs to find a file called
@file{ALongFileName.cc} (because the Makefile tells it to build
@file{ALongFileName.o}), make sure there indeed is such a file in the
directory. Many times people use archive tools (like @code{PKZIP}) that
truncate long names, even on Win95, when they open an archive, which
leaves you with names like @file{alongfil.cc}, which is not the same as
the original name when LFN is supported. Be sure to use archivers that
support long filenames, e.g. use @samp{DJTAR} when you open
@file{.tar.gz} archives, or rename all the files to their original long
names after you open the archive.
@paragraph{}
If the problems persist even though the filenames are correct, you will
have to disable LFN support (set LFN=n from the DOS prompt, setting it
in @file{DJGPP.ENV} does not always works) until these problems are
fixed in some future version of DJGPP.
@node Missing separator, Zoneinfo, LFN, Miscellany
@comment node-name, next, previous, up
@section Make says ``missing separator''
@cindex Missing separator, Make error message
@cindex Makefile, first character of every command must be TAB
@cindex TAB, must be the first character of every command
@cindex TABs replaced with spaces by a text editor
@pindex Make error message ``missing separator''
@quest{When I invoke Make, it refuses to do anything and prints this
cryptic message:}
@example
makefile:10: *** missing separator. Stop.
@end example
@emph{Now what kind of excuse is that?}
@ans{} Unlike most other DOS Make programs which accept any whitespace
character at the beginning of a command in a rule, GNU Make insists that
every such line begins with a TAB. (Most other Unix Make programs also
require TABs.) Make sure that the line whose number is printed in the
error message (in this case, line 10) begins with a TAB.
@paragraph{}
There are editors that replace TABs with spaces, so even a Makefile that
used to work can become unworkable if you edit them with such an editor.
@paragraph{}
Another, more rare, cause of the above error message is if you use static
pattern rules (with the @code{%} character) incorrectly. Read the
documentation that comes with Make carefully and try to find the error.
@node Zoneinfo, FAQ format, Missing separator, Miscellany
@comment node-name, next, previous, up
@section What is in that @file{zoneinfo} directory?
@cindex Zoneinfo directory
@cindex TZ variable, how to set
@cindex TZ database updates, where to get
@quest{When I installed DJGPP v2, it created a directory named
@file{zoneinfo} with a lot of small files that take up 3.5MB of my disk
space. What are they for? Can I delete them?}
@ans{} These files exist so that time-related library functions can
correctly calculate the offset between the local time and the @dfn{UTC}
(Universal Coordinated Time). This offset is required when you get
files from another time-zone, like from the Internet, or when you
download an archive that was compressed in another time-zone. If you
don't care about file time stamps being incorrect in such cases, you can
delete all those files and never look back.
@paragraph{}
You might wonder why we need all these zoneinfo files when the UTC
offset @emph{is} required. Well, the simplest way to tell programs
what the UTC offset is, is to have the user specify a single number
which is the offset; but then this number needs to be changed twice a
year, to accommodate for the daylight saving time. Another,
not-quite-so-simple way is to have the user specify the current UTC
offset and the DST rules; but this is a tedious and error-prone process,
and many users get it wrong. Both of these methods have the drawback
that if the rules change, programs misinterpret old time-stamps, since
they treat them according to new rules. Using a table that is read from
a file and includes the offset calculation rules for every year avoids
all these problems and requires the user to point the @code{TZ}
environment variable to the file that is pertinent to his/her time zone,
which is easy:
@example
set TZ=c:/djgpp/zoneinfo/israel
@end example
@emph{or}
@example
set TZ=c:/djgpp/zoneinfo/us/alaska
@end example
To find the rule suitable for your location, look into the @file{src}
subdirectory of @file{zoneinfo} and browse the file whose name is your
continent/part of the world. If no binary file exists with the name of
your zone, you can create one with using the time-zone compiler
@samp{zic}, whose source is also in the @file{src} subdirectory.
@paragraph{}
A public domain time-zone database exists, and is updated from time to
time with the latest world-wide changes to the offset calculation rules.
(The rules change because politicians in different countries make laws
that change the local clock settings.) The contents of the
@file{zoneinfo} directory which comes with DJGPP is based on this
database, but if you want the latest rules, you can @ftp{download them
from the net, elsie.nci.nih.gov/pub/} as @file{tzdata*.tar.gz};
@file{tzcode*.tar.gz} in the same directory includes the programs that
can be used to generate the offset tables from their source in
@file{tzdata*.tar.gz}, the latest implementations of POSIX library
functions that use time-zone information, and the man pages that
document the rules and the software. The last update as of this writing
was in May 1996.
@paragraph{}
On any single machine, you don't need more than a single file from that
directory, which is the file for your time zone; once you find that
file, you can safely delete the rest. But if you distribute a program
that uses the TZ setting, you will have to include all of the files, or
tell your users how to get and install them.
@paragraph{}
@node FAQ format, , Zoneinfo, Miscellany
@comment node-name, next, previous, up
@section Generating the FAQ in your favorite format
@cindex FAQ, conversion to different formats
@cindex Conversion of the FAQ to different formats
@pindex MAKERTF, produces the FAQ in RTF format
@pindex INFNG, produces the FAQ in Norton Guides format
@quest{How can I generate the FAQ list in a format I'm used to?}
@ans{} First, you need to get the FAQ sources. The sources of the
latest version of this FAQ list can always be found as
@file{faq@value{faq-version}s.zip} @ftp{on DJ Delorie's server,
ftp.delorie.com/pub/djgpp/v2faq/faq@value{faq-version}s.zip} and @ftp{on
SimTel mirrors,
@SimTel{}/pub/simtelnet/gnu/djgpp/v2/faq@value{faq-version}s.zip}.
This includes the source file (written in Texinfo), and all the auxiliary
tools required to produce the Info, plain-ASCII, HTML, and a few other
versions of the FAQ list; the FAQ in all these formats is available in
a separate ZIP archive as @file{faq@value{faq-version}b.zip} @ftp{from
DJ Delorie's server,
ftp.delorie.com/pub/djgpp/v2faq/faq@value{faq-version}b.zip} or
@ftp{from SimTel mirrors,
@SimTel{}/pub/simtelnet/gnu/djgpp/v2/faq@value{faq-version}b.zip}.
Currently, this includes the Info version, the text (ASCII) version and
an HTML version as a single large @file{.html} file. More formats will
be available as the tools for their generation are developed/tested.
@paragraph{}
If none of these formats is good enough for you, here are some tools
available to generate the FAQ list in other formats. If you know about
any format not mentioned below that can be generated using widely
available tools, please drop me a note so I could update this list and
consider that format or those tools for inclusion in a future release of
the FAQ. If you develop any such tools, consider uploading them to a
site where they will be publicly available, and tell me about that site.
@paragraph{}
Note that the FAQ source is a heavy user of the Texinfo macro facility,
so any conversion program that doesn't support Texinfo macros will
probably have hard time coping with the FAQ. When confronted with this
problem try feeding the converter with the macro-expanded version of the
FAQ (the Makefile in the source distribution has a special target for
such cases).
@paragraph{}
A program called @samp{Makertf} can reportedly be used to convert a
Texinfo sources of this FAQ to the @dfn{Rich File Format} which can then
either be browsed by an RTF browser (such as Adobe Acrobat) or converted
into a Windows Help file with a Windows Help compiler. @samp{Makertf}
is available @ftp{from CCT mirrors,
@CCT{}/Coast/win3/winhelp/mkrtf104.zip}. The Windows Help Compiler is
available via anonymous ftp @ftp{from the Microsoft ftp site,
ftp.microsoft.com/Softlib/MSFILES/HC305.EXE}.
@paragraph{}
There also a program called @samp{INFNG} that can be used to convert
the Info (@strong{not} Texinfo) version of the FAQ to the Norton Guide
format. @samp{INFNG} can be downloaded from @ftp{the DJGPP archive,
@SimTel{}/pub/simtelnet/gnu/djgpp/v2misc/infng100.zip}.
@paragraph{}
@node About, Topic Index, Miscellany, Top
@comment node-name, next, previous, up
@chapter About this FAQ
Maintainer: @mail{Eli Zaretskii, eliz@@is.elta.co.il}.
@paragraph{}
This FAQ is Copyright @copyright{} 1994, 1995, 1996 by
@mail{Eli Zaretskii, eliz@@is.elta.co.il}. It may be freely
redistributed with the DJGPP package or any part thereof, provided that
you don't prevent anybody else from redistributing it on the same terms,
and that this copyright notice is left intact.
@paragraph{}
Comments about, suggestions for, or corrections to this FAQ list are
welcome. Please make sure to include in your mail the version number of
the document to which your comments apply (you can find the version at the
beginning of this FAQ list).
@paragraph{}
Much of the info in this FAQ list was taken from the DJGPP mailing
list/news group traffic, so many of you have (unbeknownst to you)
contributed to this list. The following people read this list in its
previous versions and provided useful feedback, comments, information
and/or suggestions:
@display
@mail{John M. Aldrich, fighteer@@cs.com}
@mail{Anthony Appleyard, A.APPLEYARD@@fs2.mt.umist.ac.uk}
@mail{John Bodfish, bodfish@@austen.notis.com}
@mail{Bill Davidson, bdavidson@@ra.isisnet.com}
@mail{Francois Charton, deef@@pobox.oleane.com}
@mail{Bill Currie, bill_currie@@MAIL.TAIT.CO.NZ}
@DJ{}
@mail{Juergen Erhard, jae@@laden.ilk.de}
@mail{Jeremy Filliben, prime@@UDel.Edu}
@mail{James W. Haefner, Jim@@anolis.bnr.usu.edu}
@mail{Koen Van Herck, kvhk@@barco.com}
@mail{Robert Hoehne, Robert.Hoehne@@Mathematik.TU-Chemnitz.DE}
@mail{Gordon Hogenson, ghogenso@@u.washington.edu}
@mail{Harry Johnston, omega@@es.co.nz}
@mail{Martynas Kunigelis, martynas.kunigelis@@vm.ktu.lt}
@mail{Pieter Kunst, kunst@@prl.philips.nl}
@mail{Y. Lazarovitch, yitzg@@haven.ios.com}
@mail{Alexander Lehmann, lehmann@@mathematik.th-darmstadt.de}
@mail{Marty Leisner, leisner@@sdsp.mc.xerox.com}
@mail{Dave Love, d.love@@dl.ac.uk}
@mail{Rob Nader, naderr@@topaz.cqu.edu.au}
@mail{Eric Nicolas, nicolas@@JUPITER.saclay.cea.fr}
@mail{Elliott Oti, e.oti@@stud.warande.ruu.nl}
@mail{Esa A E Peuha, peuha@@cc.helsinki.fi}
@mail{Walter Prins, prins@@quark.cs.sun.ac.za}
@mail{Steve Salter, salters@@admin.fanshawec.on.ca}
@CWS{}
@mail{Terrel Shumway, Shumw001@@Cerritos.edu}
@mail{Andrew Szymkowiak, aes@@solia.gsfc.nasa.gov}
@mail{Launey Thomas, ljt@@sierrasemi.com}
@mail{Chris Tilbury, C.J.Tilbury@@estate.warwick.ac.uk}
@Steve{}
@mail{Santiago Vila, sanvila@@pizarro.unex.es}
@mail{Ronan Waide, waider@@waider.ie}
@mail{Morten Welinder, terra@@diku.dk}
@mail{Anthony Edward Wesley, awesley@@galaxy.anutech.com.au}
@mail{Mark H. Wood, mwood@@mhw.OIT.IUPUI.EDU}
@end display
@node Topic Index, Program Index, About, Top
@comment node-name, next, previous, up
@chapter Topic Index
This is an alphabetical list of all the topics covered in this FAQ. Use
it to search for a description of your problem and follow the link to find
the answer(s).
@ifset html
@*
@*
@include concepts.idx
@*
@*
@end ifset
@ifclear html
@printindex cp
@end ifclear
@node Program Index, , Topic Index, Top
@comment node-name, next, previous, up
@chapter Program Index
This index lists the problems and solutions by the program/package to
which they pertain. If you know what program or package gives you the
trouble, look it up here.
@ifset html
@*
@*
@include programs.idx
@*
@*
@end ifset
@ifclear html
@printindex pg
@end ifclear
@contents
@bye
@c Local Variables:
@c time-stamp-line-limit:15
@c time-stamp-start:"^@set update-date "
@c time-stamp-end:"$"
@c time-stamp-format:"%d %b %y"
@c eval:(require 'time-stamp)
@c eval:(add-hook 'write-file-hooks 'time-stamp)
@c End:
This document was generated on November 6, 2024 using texi2html 5.0.