www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Compiling DMD with C++11

reply "Andre Artus" <andre.artus gmail.com> writes:
I decided to see whether dmd would compile with VS2013 and Clang. 
So far the only issue seems to be that C++11 RTL already defines 
'strtold'.

http://www.cplusplus.com/reference/cstdlib/strtold/

Compiling results in the following error:

Error	1	error C2556: 'longdouble strtold(const char *,char **)' : 
overloaded function differs only by return type from 'long double 
strtold(const char *,char 
**)'	d:\source\github\d\dmd\src\root\longdouble.h	201	1	dmd_msc

I have not used C++ in a very long time (cannot believe I used to 
love it, now it looks so ugly).

I can build against the VS2012 libraries, but that defeats the 
purpose of the exercise for me.

Is there a way to hide cstdlib/strtold?

I could refactor the code to rename dmd/strtold, but that may not 
go down well (play nice with others).

I also get the following warnings (when compiling in VS2012):

Warning	1	warning C4805: '!=' : unsafe mix of type 'char' and 
type 'bool' in 
operation	D:\source\GitHub\D\dmd\src\mars.c	1031	1	dmd_msc 
(Visual Studio 2012)

Warning	2	warning C4700: uninitialized local variable 'i' 
used	d:\source\github\d\dmd\src\backend\cgcod.c	2204	1	dmd_msc 
(Visual Studio 2012)

Warning	3	warning C4805: '==' : unsafe mix of type 'bool' and 
type 'int' in 
operation	D:\source\GitHub\D\dmd\src\backend\divcoeff.c	284	1	dmd_msc 
(Visual Studio 2012)

I tend to treat warnings as errors in my own code, which I 
relaxed here in order to get a working build.
Aug 05 2013
next sibling parent "Andre Artus" <andre.artus gmail.com> writes:
I see there is quite a lot of code commented out with '#if 0', 
most of which looks like testing code. Unit tests in D is one of 
the 'killer' features. THE killer D feature for me is 'scope'.

I bring this up because I see

extern "C" longdouble strtold(const char *p,char **endp);
//strtold.c(583, 23):

is in one of those blocks. If 'strtold' had to change names who 
would be affected by it?
Aug 05 2013
prev sibling next sibling parent "Andre Artus" <andre.artus gmail.com> writes:
I forgot about the joys of C++, e.g. the code, build, make 
coffee, read forum posts, run, cycle.
Aug 05 2013
prev sibling next sibling parent reply "Andre Artus" <andre.artus gmail.com> writes:
 I could refactor the code to rename dmd/strtold, but that may 
 not go down well (play nice with others).
I did a rename refactor on strtold (changed it to strtolongdouble) for S&G and everything seems to work just fine for VC++ 2013.
Aug 05 2013
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Aug 06, 2013 at 02:38:43AM +0200, Andre Artus wrote:
I could refactor the code to rename dmd/strtold, but that may not
go down well (play nice with others).
I did a rename refactor on strtold (changed it to strtolongdouble) for S&G and everything seems to work just fine for VC++ 2013.
Nice, does it pass the unittests? T -- Lottery: tax on the stupid. -- Slashdotter
Aug 05 2013
prev sibling next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Andre Artus:

 I decided to see whether dmd would compile with VS2013 and 
 Clang. So far the only issue seems to be that C++11 RTL already 
 defines 'strtold'.
I suggest to put most of those small bug reports in Bugzilla (or better if you want as a patch in GitHub to fix them). Bye, bearophile
Aug 06 2013
parent reply "Andre Artus" <andre.artus gmail.com> writes:
On Tuesday, 6 August 2013 at 16:18:54 UTC, bearophile wrote:
 Andre Artus:

 I decided to see whether dmd would compile with VS2013 and 
 Clang. So far the only issue seems to be that C++11 RTL 
 already defines 'strtold'.
I suggest to put most of those small bug reports in Bugzilla (or better if you want as a patch in GitHub to fix them). Bye, bearophile
I 'fixed' it in my copy. By that I mean it compiles and runs on my system, but no code in other conditional compilation path has changed, so it will break say on *nix etc. I currently only work on Mac and Windows, my Linux & BSD boxes were stolen. If there is agreement with the new name, or if a better alternative is offered then I will be more than happy to make a comprehensive change. I'm not sure if it classifies as a bug though, as there is no reason why DMD *has* to compile with C++11 libraries; it was just an experiment I tried. I'm not sure that "strtolongdouble" fits in with the naming convention but I decided to choose something that would be easy to grep if I needed to do so. The all lowercase convention prevalent in C causes a little bit of sick to rise in my throat every time I see it. When I first saw 'strtold' my brain picked up 'str to old', as opposed to 'str to l d'. I normally try to write code in a way that someone with no prior experience may reasonably infer it's function merely from looking at the signature. I'll refactor several times if need be (while maintaining the contract on published interfaces where need be). But, when climbing into an established codebase it is prudent to follow existing conventions; I have not yet determined what they are for DMD. I take it there is a doc or page up about that somewhere.
Aug 06 2013
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Andre Artus:

 If there is agreement with the new name, or if a better 
 alternative is offered then I will be more than happy to make a 
 comprehensive change.
I didn't talk about the strtosomething name, I was referring to everything else you have found, the warnings. Bye, bearophile
Aug 06 2013
parent reply "Andre Artus" <andre.artus gmail.com> writes:
On Tuesday, 6 August 2013 at 22:38:58 UTC, bearophile wrote:
 Andre Artus:

 If there is agreement with the new name, or if a better 
 alternative is offered then I will be more than happy to make 
 a comprehensive change.
I didn't talk about the strtosomething name, I was referring to everything else you have found, the warnings. Bye, bearophile
Okay. I already changed those in my copy. Just out of interest: what would be an acceptable name to change 'strtold' to?
Aug 06 2013
next sibling parent reply "David Nadlinger" <code klickverbot.at> writes:
On Tuesday, 6 August 2013 at 22:58:21 UTC, Andre Artus wrote:
 Okay. I already changed those in my copy.
 Just out of interest: what would be an acceptable name to 
 change 'strtold' to?
strtold is a C standard library function, but due to the portability problems the actual compiler code should use Port::strtold: https://github.com/D-Programming-Language/dmd/blob/master/src/root/port.h#L59 (OTOH, some backend/* code might pull it in directly, though). As for what name to use for the internal implementation of Port::strtold on MSVC, you can pretty much pick whatever you like, as it shouldn't affect any other code. David
Aug 07 2013
parent "Andre Artus" <andre.artus gmail.com> writes:
On Wednesday, 7 August 2013 at 08:18:26 UTC, David Nadlinger 
wrote:
 On Tuesday, 6 August 2013 at 22:58:21 UTC, Andre Artus wrote:
 Okay. I already changed those in my copy.
 Just out of interest: what would be an acceptable name to 
 change 'strtold' to?
strtold is a C standard library function, but due to the portability problems the actual compiler code should use Port::strtold: https://github.com/D-Programming-Language/dmd/blob/master/src/root/port.h#L59 (OTOH, some backend/* code might pull it in directly, though). As for what name to use for the internal implementation of Port::strtold on MSVC, you can pretty much pick whatever you like, as it shouldn't affect any other code. David
I'm not near my Windows PC right now, but if memory serves the name clash occurs in the following places: https://github.com/D-Programming-Language/dmd/blob/master/src/backend/strtold.c?source=cc#L138 https://github.com/D-Programming-Language/dmd/blob/master/src/root/longdouble.h#L201 https://github.com/D-Programming-Language/dmd/blob/master/src/backend/strtold.c#L567 I do not recall "Port::strtold" being a problem, other than that (if I recall correctly) it forwards to the conflicting function. https://github.com/D-Programming-Language/dmd/blob/master/src/root/port.c#L118
Aug 07 2013
prev sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Aug 07, 2013 at 12:58:16AM +0200, Andre Artus wrote:
 On Tuesday, 6 August 2013 at 22:38:58 UTC, bearophile wrote:
Andre Artus:

If there is agreement with the new name, or if a better
alternative is offered then I will be more than happy to make a
comprehensive change.
I didn't talk about the strtosomething name, I was referring to everything else you have found, the warnings. Bye, bearophile
Okay. I already changed those in my copy. Just out of interest: what would be an acceptable name to change 'strtold' to?
Maybe strtold_dmd? Or you could just post the pull request and let the reviewers suggest a better name if they don't like your choice. :) T -- "I'm not childish; I'm just in touch with the child within!" - RL
Aug 06 2013
prev sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Aug 07, 2013 at 12:10:33AM +0200, Andre Artus wrote:
 On Tuesday, 6 August 2013 at 16:18:54 UTC, bearophile wrote:
Andre Artus:

I decided to see whether dmd would compile with VS2013 and
Clang. So far the only issue seems to be that C++11 RTL already
defines 'strtold'.
I suggest to put most of those small bug reports in Bugzilla (or better if you want as a patch in GitHub to fix them). Bye, bearophile
I 'fixed' it in my copy. By that I mean it compiles and runs on my system, but no code in other conditional compilation path has changed, so it will break say on *nix etc. I currently only work on Mac and Windows, my Linux & BSD boxes were stolen.
Did you run the test suite? If it passes the test suite, I'd say submit a pull request to rename that function.
 If there is agreement with the new name, or if a better alternative
 is offered then I will be more than happy to make a comprehensive
 change.
 
 I'm not sure if it classifies as a bug though, as there is no reason
 why DMD *has* to compile with C++11 libraries; it was just an
 experiment I tried.
I think it would only benefit us to have DMD compilable under C++11. I know this currently isn't officially supported, but if it can be made to work, why not?
 I'm not sure that "strtolongdouble" fits in with the naming
 convention but I decided to choose something that would be easy to
 grep if I needed to do so. The all lowercase convention prevalent in
 C causes a little bit of sick to rise in my throat every time I see
 it. When I first saw 'strtold' my brain picked up 'str to old', as
 opposed to 'str to l d'.
This is just sticking with the C library conventions (strtol, strtod, etc.). Honestly, I prefer all lowercase identifiers; I find camelCasing very jarring and unpleasant to the eye. But it's just a matter of personal preference, so I can live with it. :)
 I normally try to write code in a way that someone with no prior
 experience may reasonably infer it's function merely from looking at
 the signature.
Anyone familiar with the standard C library strtol, strtod & co., will have no problems correctly guessing what strtold does. It's just a different convention from the prevalent camelCasing thing, that's all. Of course, I wouldn't use such names when writing D code, but y'know, it eventually just a matter of convention. :)
 I'll refactor several times if need be (while maintaining the contract
 on published interfaces where need be). But, when climbing into an
 established codebase it is prudent to follow existing conventions; I
 have not yet determined what they are for DMD.  I take it there is a
 doc or page up about that somewhere.
For Phobos & druntime there are established coding standards: http://dlang.org/dstyle.html But since DMD is written in C++, I'd say just follow whatever prevalent style is in the source code you're contributing to. T -- If you think you are too small to make a difference, try sleeping in a closed room with a mosquito. -- Jan van Steenbergen
Aug 06 2013
prev sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Aug 06, 2013 at 01:59:28AM +0200, Andre Artus wrote:
 I decided to see whether dmd would compile with VS2013 and Clang. So
 far the only issue seems to be that C++11 RTL already defines
 'strtold'.
 
 http://www.cplusplus.com/reference/cstdlib/strtold/
 
 Compiling results in the following error:
 
 Error	1	error C2556: 'longdouble strtold(const char *,char **)' :
 overloaded function differs only by return type from 'long double
 strtold(const char *,char
 **)'	d:\source\github\d\dmd\src\root\longdouble.h	201	1	dmd_msc
 
 I have not used C++ in a very long time (cannot believe I used to
 love it, now it looks so ugly).
 
 I can build against the VS2012 libraries, but that defeats the
 purpose of the exercise for me.
 
 Is there a way to hide cstdlib/strtold?
[...] One way that occurs to me, but which unfortunately as Very Ugly, is to #define strtold into something else. If standard lib headers are always #include'd first, and dmd internal headers after, then putting: #define strtold strtold_dmd in the header in dmd that defines the function should fix the problem. It *is* an extremely ugly hack, though. Now excuse me as I go to wash my hands... :-P T -- PNP = Plug 'N' Pray
Aug 05 2013