www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DMD Source question

reply Paul Bonser <misterpib gmail.com> writes:
I was just looking at the dmd front-end source and I noticed that all 
the source files are .c

Isn't it written in C++? Just a kinda random question as to why all of 
the files have the c extention.

-PIB
Jan 17 2005
parent reply "Nick Sabalausky" <z a.a> writes:
 Isn't it written in C++? Just a kinda random question as to why all of the 
 files have the c extention.

 -PIB
It's recommended convention for C++ sources and headers to use" .cpp" and ".hpp" respectively, but not everyone follows it and compilers aren't very picky about it anyway. I'm guessing it was fairly arbitrary, he was probably just accustomed to using ".c".
Jan 17 2005
next sibling parent reply Gold Dragon <dragonwing dragonu.net> writes:
 It's recommended convention for C++ sources and headers to use" .cpp" and 
 ".hpp" respectively, but not everyone follows it and compilers aren't very 
 picky about it anyway. I'm guessing it was fairly arbitrary, he was probably 
 just accustomed to using ".c". 
I thought it /was/ written in C. People do still write C code because it does have it uses in low level OS programming and some other DLL stuff that C++ can't do because of the Design of the language.
Jan 18 2005
parent Paul Bonser <misterpib gmail.com> writes:
Gold Dragon wrote:
 It's recommended convention for C++ sources and headers to use" .cpp" 
 and ".hpp" respectively, but not everyone follows it and compilers 
 aren't very picky about it anyway. I'm guessing it was fairly 
 arbitrary, he was probably just accustomed to using ".c". 
I thought it /was/ written in C. People do still write C code because it does have it uses in low level OS programming and some other DLL stuff that C++ can't do because of the Design of the language.
I know that people still write in C, it's just that DMD isn't. -PIB
Jan 18 2005
prev sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Nick Sabalausky wrote:

 It's recommended convention for C++ sources and headers to use" .cpp" and 
 ".hpp" respectively, but not everyone follows it and compilers aren't very 
 picky about it anyway. I'm guessing it was fairly arbitrary, he was probably 
 just accustomed to using ".c". 
Another valid extension for C++ is ".cc". A single ".c" means C code. Many things are written in C to avoid the overhead of the C++ libraries. Header files are very rarely compiled by themselves, so most use ".h" for them - for both the languages. Even if that is not really correct... The only thing that uses C++ in DMD is "recls": src/phobos/etc/c/recls (in the DMD front-end and download that is, no idea about the back-end) See http://synesis.com.au/software/recls/ --anders
Jan 18 2005
next sibling parent reply Paul Bonser <misterpib gmail.com> writes:
Anders F Björklund wrote:
 Nick Sabalausky wrote:
 
 It's recommended convention for C++ sources and headers to use" .cpp" 
 and ".hpp" respectively, but not everyone follows it and compilers 
 aren't very picky about it anyway. I'm guessing it was fairly 
 arbitrary, he was probably just accustomed to using ".c". 
Another valid extension for C++ is ".cc". A single ".c" means C code. Many things are written in C to avoid the overhead of the C++ libraries. Header files are very rarely compiled by themselves, so most use ".h" for them - for both the languages. Even if that is not really correct... The only thing that uses C++ in DMD is "recls": src/phobos/etc/c/recls (in the DMD front-end and download that is, no idea about the back-end) See http://synesis.com.au/software/recls/ --anders
Apparently not everyone has looked very closely at the DMD code: struct Token { Token *next; unsigned char *ptr; // pointer to first character of this token within buffer enum TOK value; ... static char *tochars[TOKMAX]; static void *operator new(size_t sz); void print(); char *toChars(); static char *toChars(enum TOK); }; Looks an awful lot like C++ to me ;) -PIB
Jan 18 2005
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Paul Bonser wrote:

 The only thing that uses C++ in DMD is "recls": src/phobos/etc/c/recls
 (in the DMD front-end and download that is, no idea about the back-end)> 
Apparently not everyone has looked very closely at the DMD code:
[...]
 Looks an awful lot like C++ to me ;)
Guilty as charged... Putting C++ code in .c files is a horrible thing to do! (not only GCC, but a lot of readers assume it is plain C) --anders
Jan 18 2005
prev sibling next sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Anders F Björklund" <afb algonet.se> wrote in message
news:csih3l$khr$2 digitaldaemon.com...
 Nick Sabalausky wrote:

 It's recommended convention for C++ sources and headers to use" .cpp"
and
 ".hpp" respectively, but not everyone follows it and compilers aren't
very
 picky about it anyway. I'm guessing it was fairly arbitrary, he was
probably
 just accustomed to using ".c".
Another valid extension for C++ is ".cc". A single ".c" means C code. Many things are written in C to avoid the overhead of the C++ libraries. Header files are very rarely compiled by themselves, so most use ".h" for them - for both the languages. Even if that is not really correct...
Back in the early days of C++, it was common to use .hpp for C++ header files. For some reason or other, this fell into disuse, and people just began using .h. It's become more and more common to drop the .cpp suffix in favor of .c, too.
 The only thing that uses C++ in DMD is "recls": src/phobos/etc/c/recls
 (in the DMD front-end and download that is, no idea about the back-end)
The DMD front end does not use recls. The D runtime library, Phobos, has recls included in it. Recls is a demonstration of how to connect C++ code to D. DMD is most definitely written in C++, but a fairly simple subset of it. It doesn't rely on STL, iostreams, exception handling, templates, or even RTTI. (This makes the source portable to a much wider variety of C++ compilers.) It does use a garbage collector. It wouldn't be hard to translate the DMD front end into D, but then it would be very hard to connect it to back ends like gcc's.
Jan 18 2005
parent Norbert Nemec <Norbert Nemec-online.de> writes:
Walter wrote:

 
 "Anders F Björklund" <afb algonet.se> wrote in message
 news:csih3l$khr$2 digitaldaemon.com...
 Nick Sabalausky wrote:

 It's recommended convention for C++ sources and headers to use" .cpp"
and
 ".hpp" respectively, but not everyone follows it and compilers aren't
very
 picky about it anyway. I'm guessing it was fairly arbitrary, he was
probably
 just accustomed to using ".c".
Another valid extension for C++ is ".cc". A single ".c" means C code. Many things are written in C to avoid the overhead of the C++ libraries. Header files are very rarely compiled by themselves, so most use ".h" for them - for both the languages. Even if that is not really correct...
Back in the early days of C++, it was common to use .hpp for C++ header files. For some reason or other, this fell into disuse, and people just began using .h. It's become more and more common to drop the .cpp suffix in favor of .c, too.
"More and more common" probably is open to debate. I've seen many open source projects and can remember none that used .c for C++ files. I've seen .cpp, .cxx, .C and .cc with a slight majority on .cpp Some compiler (e.g. gcc) distinguish their sources by the file extension, so using .c for C++ code really is not a good idea. Furthermore, some editors distinguish between them for syntax highlighting as well. Not to mention the confusion of everyone who sees the code. For header files, though, .h is indeed very common. I have no idea why. Even if these files are not compiled, editors certainly choke on them as well. Even if the abuse of the .c extension might become "more and more common" I really don't think it is a good idea to follow this trend. (Maybe, the gcc is the cause why nobody ever started it on Linux...)
Jan 18 2005
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Anders F Björklund wrote:
<snip>
 Another valid extension for C++ is ".cc". A single ".c" means C code.
There are a number of extensions sometimes used to refer to C++. GCC claims to recognise these: .cpp .c++ .cxx .cc .cp .C Of course, whether .c++ is possible and whether .C is distinct from .c are platform dependent. A bit annoyingly, tcsh refuses to autocomplete to anything but .C or .cc as an argument to gcc or g++.
 Many things are written in C to avoid the overhead of the C++ libraries.
<snip> But the libraries don't all have to be linked in, do they? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 18 2005
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Stewart Gordon wrote:

 Another valid extension for C++ is ".cc". A single ".c" means C code.
There are a number of extensions sometimes used to refer to C++.
Yet another reason to use D...
 Many things are written in C to avoid the overhead of the C++ libraries.
But the libraries don't all have to be linked in, do they?
That is also platform dependant. --anders
Jan 18 2005
parent "Walter" <newshound digitalmars.com> writes:
"Anders F Björklund" <afb algonet.se> wrote in message
news:csj1qg$197g$1 digitaldaemon.com...
 Stewart Gordon wrote:

 Another valid extension for C++ is ".cc". A single ".c" means C code.
There are a number of extensions sometimes used to refer to C++.
Yet another reason to use D...
It's unfortunate that C++ never standardized on an extension.
Jan 18 2005