Jump to page: 1 2
Thread overview
DMD Source question
Jan 18, 2005
Paul Bonser
Jan 18, 2005
Nick Sabalausky
Jan 18, 2005
Gold Dragon
Jan 18, 2005
Paul Bonser
Jan 18, 2005
Paul Bonser
Jan 18, 2005
Walter
Jan 18, 2005
Norbert Nemec
Jan 18, 2005
Stewart Gordon
Jan 18, 2005
Walter
January 18, 2005
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
January 18, 2005
> 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".


January 18, 2005
> 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.
January 18, 2005
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
January 18, 2005
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
January 18, 2005
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
January 18, 2005
"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.


January 18, 2005
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...)

January 18, 2005
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
January 18, 2005
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.
« First   ‹ Prev
1 2