Jump to page: 1 2
Thread overview
Why is Linux the only OS in version identifier list that has a lowercase name?
Apr 10, 2016
Zekereth
Apr 11, 2016
Mike Parker
Apr 11, 2016
Zekereth
Apr 11, 2016
Ali Çehreli
Apr 11, 2016
Zekereth
Apr 11, 2016
marcpmichel
Apr 12, 2016
Brian Schott
Apr 12, 2016
Zekereth
Apr 12, 2016
Jonathan M Davis
Apr 12, 2016
Jonathan M Davis
April 10, 2016
So I was just testing some code and couldn't figure out why it wasn't working. My version block looked like this:

version(Linux)
{
...
}

Looking at the list(unless I'm missing something) Linux is the only OS that is lowercase. I'm guessing most people use Posix instead and never encounter this problem.

Regard,
Zekereth
April 11, 2016
On Sunday, 10 April 2016 at 22:03:54 UTC, Zekereth wrote:
> So I was just testing some code and couldn't figure out why it wasn't working. My version block looked like this:
>
> version(Linux)
> {
> ...
> }
>
> Looking at the list(unless I'm missing something) Linux is the only OS that is lowercase. I'm guessing most people use Posix instead and never encounter this problem.
>

It's an artifact of history. When this was first introduced, Walter's intent was to match the casing used in gcc preprocessor definitions. Since that time, we've standardized on capitalization for everything, but 'linux' lives on. I would like to see 'Linux' introduced for consistency and to avoid errors like yours (a bug lived in Phobos for a long time because of this) while maintaining 'linux' for backwards compatibility.
April 10, 2016
On 04/10/2016 03:03 PM, Zekereth wrote:
> So I was just testing some code and couldn't figure out why it wasn't
> working. My version block looked like this:
>
> version(Linux)
> {
> ...
> }
>
> Looking at the list(unless I'm missing something) Linux is the only OS
> that is lowercase. I'm guessing most people use Posix instead and never
> encounter this problem.
>
> Regard,
> Zekereth

As a workaround, you can set version to Linux yourself:

version (linux) {
    version = Linux;
}

void main() {
    version (Linux) {
        import std.stdio;
        writeln("Linux worked!");
    }
}

April 11, 2016
On Monday, 11 April 2016 at 00:51:19 UTC, Mike Parker wrote:
> It's an artifact of history. When this was first introduced, Walter's intent was to match the casing used in gcc preprocessor definitions. Since that time, we've standardized on capitalization for everything, but 'linux' lives on. I would like to see 'Linux' introduced for consistency and to avoid errors like yours (a bug lived in Phobos for a long time because of this) while maintaining 'linux' for backwards compatibility.

Thanks, that makes sense. It would be nice if Linux could be introduced. I'll just have to remember from now on. Thanks again!
April 11, 2016
On Monday, 11 April 2016 at 01:15:27 UTC, Ali Çehreli wrote:
> As a workaround, you can set version to Linux yourself:
>
> version (linux) {
>     version = Linux;
> }
>
> void main() {
>     version (Linux) {
>         import std.stdio;
>         writeln("Linux worked!");
>     }
> }

That's interesting that will help. Thanks for that!
April 11, 2016
On Sunday, 10 April 2016 at 22:03:54 UTC, Zekereth wrote:
> Looking at the list(unless I'm missing something) Linux is the only OS that is lowercase.

Is it because Linux is not an OS ? :p

April 12, 2016
On Monday, 11 April 2016 at 23:01:08 UTC, marcpmichel wrote:
> Is it because Linux is not an OS ? :p

I gnu somebody would bring that up.

April 12, 2016
On Tuesday, 12 April 2016 at 01:32:02 UTC, Brian Schott wrote:
> On Monday, 11 April 2016 at 23:01:08 UTC, marcpmichel wrote:
>> Is it because Linux is not an OS ? :p
>
> I gnu somebody would bring that up.

/sigh so did I.
April 12, 2016
On 4/10/16 9:19 PM, Zekereth wrote:
> On Monday, 11 April 2016 at 01:15:27 UTC, Ali Çehreli wrote:
>> As a workaround, you can set version to Linux yourself:
>>
>> version (linux) {
>>     version = Linux;
>> }
>>
>> void main() {
>>     version (Linux) {
>>         import std.stdio;
>>         writeln("Linux worked!");
>>     }
>> }
>
> That's interesting that will help. Thanks for that!

I highly recommend not to do this. New version assignments do not live outside the module, so you have to do this in EVERY module you want to use it.

Better to pass on the command line. Even better to just use the standard version identifier :)

-Steve
April 12, 2016
On Tuesday, 12 April 2016 at 01:32:02 UTC, Brian Schott wrote:
> On Monday, 11 April 2016 at 23:01:08 UTC, marcpmichel wrote:
>> Is it because Linux is not an OS ? :p
>
> I gnu somebody would bring that up.

There's actually a serious point here, though -- as D is ported to other platforms and architectures, it's going to wind up being used to target environments that use a Linux kernel but are not GNU.  Conversely, there may also be systems that are GNU but not Linux (e.g. the recent proposal for an Ubuntu flavour based on the FreeBSD kernel).

Are druntime and phobos ready to deal with those kinds of eventuality?
« First   ‹ Prev
1 2