standard header files

J

jayceechong

If I write my own C compiler, can I just "take" existing standard
header files (e.g. stdio.h, stdlib.h, etc.) from an existing C compiler
and plug them in my own? I understand I have to write my own library
implementations, but what about these header files? Thanks!
 
K

Keith Thompson

If I write my own C compiler, can I just "take" existing standard
header files (e.g. stdio.h, stdlib.h, etc.) from an existing C compiler
and plug them in my own? I understand I have to write my own library
implementations, but what about these header files? Thanks!

Maybe.

Note that the standard headers don't necessarily have to be files,
though they usually are.

If the header files already on the system don't use any
compiler-specific features (or use them only protected by appropriate
#ifdefs), you should be ok. Or you might do something like gcc's
"fix-headers", which, during installation, makes modified copies of
the system headers.

For that matter, there's no real reason why you should have to write
your own library implementations. gcc, for example, uses whatever C
library exists on the system.
 
M

Michael Mair

If I write my own C compiler, can I just "take" existing standard
header files (e.g. stdio.h, stdlib.h, etc.) from an existing C compiler
and plug them in my own? I understand I have to write my own library
implementations, but what about these header files? Thanks!

There is no requirement at all that these other header files
- exist (the compiler may implement them internally)
- contain standard C (black magic may be used)
- will work with any other C compiler

It may be instructive to have a look at these headers and
copy function prototypes and standard macro definitions
(or strip other things) but you should not take them as
they are without having a look.

Alternatively, do what a good compiler writer does and have
a look at the C standard. The C99 standard is available as
PDF for 18 USD, the last public draft, N869.pdf, for free.
If you want, have a look at N1124.pdf, the current last
public draft.

Cheers
Michael
 
C

CBFalconer

If I write my own C compiler, can I just "take" existing standard
header files (e.g. stdio.h, stdlib.h, etc.) from an existing C
compiler and plug them in my own? I understand I have to write my
own library implementations, but what about these header files?

Since the headers describe the library, what do you think?

--
"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/>
 
O

osmium

If I write my own C compiler, can I just "take" existing standard
header files (e.g. stdio.h, stdlib.h, etc.) from an existing C compiler
and plug them in my own? I understand I have to write my own library
implementations, but what about these header files? Thanks!

I don't know what prompted the question. But if it is from a
patent/copyright point of view, I don't think any person or organization
owns the intellectual property contained in ISO whatever. I would much
prefer using that as a source to some actual implantation, it seems a lot
safer and better in the long run.

IANAL. Thank God.
 
K

Kenneth Brody

Michael said:
There is no requirement at all that these other header files
- exist (the compiler may implement them internally)
- contain standard C (black magic may be used)
- will work with any other C compiler

Well, he did say "if I write my own C compiler". So, even if the headers
do contain black magic, they can still work with his compiler as long as
he implements the same black magic.

Of course, he might not be able to distribute those header files if they're
copyrighted.

[...]

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top