Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 01, 2014 DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Hi everyone. I think it's need to have -w64(or other name, offers ?) flag that warns if code may not compile on other archs. Example: size_t a; uint b = a; // ok on 32 without a warning but fail on 64 with error And on 32 with -w64 it'll be : Warning : size_t.sizeof may be greater than 32 bit What you thinks ? Should i create proposal or nobody cares about porting and it's useless ? Any ideas are welcome. |
May 02, 2014 Re: DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | Sounds like a nice warning. It bit me a few times when swapping architectures. |
May 02, 2014 Re: DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | On 1 May 2014 21:17, Temtaime via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> Hi everyone.
> I think it's need to have -w64(or other name, offers ?) flag that warns if
> code may not compile on other archs.
>
> Example:
> size_t a;
> uint b = a; // ok on 32 without a warning but fail on 64 with error
>
> And on 32 with -w64 it'll be :
> Warning : size_t.sizeof may be greater than 32 bit
>
> What you thinks ?
> Should i create proposal or nobody cares about porting and it's useless ?
>
> Any ideas are welcome.
Definitely a good idea. I've noticed a few of such super-helpful portability warnings don't seem to be present in D compared to other compilers.
|
May 02, 2014 Re: DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | Temtaime: > I think it's need to have -w64(or other name, offers ?) flag that warns if code may not compile on other archs. It's a problem and I'd like some way to compiler help solving such problems. I suggested this, that was refused (I don't remember who reopened it): https://issues.dlang.org/show_bug.cgi?id=5063 Bye, bearophile |
May 02, 2014 Re: DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | On Thursday, 1 May 2014 at 11:17:10 UTC, Temtaime wrote:
> Hi everyone.
> I think it's need to have -w64(or other name, offers ?) flag that warns if code may not compile on other archs.
>
> Example:
> size_t a;
> uint b = a; // ok on 32 without a warning but fail on 64 with error
>
> And on 32 with -w64 it'll be :
> Warning : size_t.sizeof may be greater than 32 bit
>
> What you thinks ?
> Should i create proposal or nobody cares about porting and it's useless ?
>
> Any ideas are welcome.
+1. Lost count how many times my Linux code wouldn't compile on Windows because of this.
Atila
|
May 02, 2014 Re: DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | On Thursday, 1 May 2014 at 11:17:10 UTC, Temtaime wrote:
> Hi everyone.
> I think it's need to have -w64(or other name, offers ?) flag that warns if code may not compile on other archs.
>
> Example:
> size_t a;
> uint b = a; // ok on 32 without a warning but fail on 64 with error
>
> And on 32 with -w64 it'll be :
> Warning : size_t.sizeof may be greater than 32 bit
>
> What you thinks ?
> Should i create proposal or nobody cares about porting and it's useless ?
>
> Any ideas are welcome.
Why not? I had some minor difficulties porting from 32 to 64bit. I think it's a good idea to let the user know beforehand that there might be problems when porting. If you find that out when you are already on a 64 or 32bit machine, it's a bit annoying to go back and change the code.
|
May 02, 2014 Re: DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | Temtaime:
> I think it's need to have -w64(or other name, offers ?) flag that warns if code may not compile on other archs.
Some of the things it has to guard against:
void main() {
size_t x;
ptrdiff_t y;
uint r1 = x; // warn
int r2 = x; // warn
uint r3 = y; // warn
int r4 = y; // warn
char[] data;
foreach (uint i, c; data) {} // warn
foreach (int i, c; data) {} // warn
}
Is something missing?
Bye,
bearophile
|
May 02, 2014 Re: DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | On Thu, 01 May 2014 11:17:09 +0000
Temtaime via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> Hi everyone.
> I think it's need to have -w64(or other name, offers ?) flag that
> warns if code may not compile on other archs.
>
> Example:
> size_t a;
> uint b = a; // ok on 32 without a warning but fail on 64 with
> error
>
> And on 32 with -w64 it'll be :
> Warning : size_t.sizeof may be greater than 32 bit
>
> What you thinks ?
> Should i create proposal or nobody cares about porting and it's
> useless ?
>
> Any ideas are welcome.
The compiler doesn't even know that size_t exists. It's just an alias in object_.d. So, it could be fairly involved to get the compiler to warn about something like this.
And while in some respects, this would be nice to have, I don't think that
it's actually a good idea. IMHO, the compiler pretty much has no business
warning about anything. As far as the compiler is concerned, everything
should be either an error or nothing (and Walter agrees with me on this;
IIRC, the only reason that he added warnings in the first place was as
an attempt to appease some folks). About the only exception would be
deprecation-related warnings, because those are items that aren't currently
errors but are going to be errors. If warnings are in the compiler,
programmers are forced to fix them as if they were errors (because it's
bad practice to leave compiler warnings in your build), and they can actually
affect what does and doesn't compile thanks to the -w flag (which can be
particularly nasty when stuff like template constraints get involved).
Warnings belong in lint-like tools where the user can control what they want to be warned about, including things that would be useful to them but most other folks wouldn't care about. So, unless you're suggesting that we make it an error to assign a value of size_t to a uint, I don't think that it makes any sense for the compiler to say anything about this, and given the fact that it doesn't know anything about size_t anyway, it's probably not particularly reasonable to have the compiler warn about it even if we agreed that it would be a good idea.
D is ideally suited to writing lint-like tools, and as I understand it, Brian Schott has written one. I don't know what state it's currently in or what exactly it can warn you about at this point, but I think that it would be better to look at putting warnings like this in such a tool than to try and get it put in the compiler.
- Jonathan M Davis
|
May 02, 2014 Re: DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 5/2/2014 12:21 PM, Jonathan M Davis via Digitalmars-d wrote: > > As far as the compiler is concerned, everything > should be either an error or nothing (and Walter agrees with me on this; It would be nice if all code *could* be considered either "good" or "error" without causing problems. But we don't live in a perfect back-and-white reality, and forcing everything into dichotomy doesn't always work out so well. > Warnings belong in lint-like tools where the user can control what they want > to be warned about, Warnings ARE a built-in lint-like tool. On top of that, lint itself proves that lint tends to not get used. If it's too hard for people to occasionally toss in a -m32 to check if that works, then no lint-like tool is going to solve the issue either. That said, I do think people are underestimating the difficulty of this enhancement, and overestimating the benefit. It's difficult because size_t is (by design) only an alias and there are issues with making it a separate type. And it's not really worth the difficulty of getting around all that because it's it's already trivially checked whenever you want by tossing in an -m32. I think this enhancement is a great *idea*, but not realistic. |
May 02, 2014 Re: DIP(?) Warning to facilitate porting to other archs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Friday, 2 May 2014 at 19:54:43 UTC, Nick Sabalausky wrote: > Warnings ARE a built-in lint-like tool. On top of that, lint itself proves that lint tends to not get used. If it's too hard for people to occasionally toss in a -m32 to check if that works, then no lint-like tool is going to solve the issue either. One solution to this is to have your editor run the lint tool: http://i.imgur.com/w7SgbnN.png |
Copyright © 1999-2021 by the D Language Foundation