View mode: basic / threaded / horizontal-split · Log in · Help
October 29, 2005
a slew of questions about D...
1) can you do ... int function(const value) in D? or function(int value) 
const?

2) can you do versioning like...

static if (version == ONE || version == TWO)

or version(!Windows)

?

or what about...

version( ONE || !TWO)


3) can D do default values like c++? function(int num = 0)
and you can either call function() for function(5)


4) How would I convert the command #pragma warning( disable : 4800 ) to 
D? I'm not too keen on pragmas.


Thanks

~ Clay
October 29, 2005
Re: a slew of questions about D...
clayasaurus wrote:
> 1) can you do ... int function(const value) in D? or function(int value) 
> const?
Technically (as I understand it) no.  Although it may not be /as/ neccessary.

> 2) can you do versioning like...
> 
> static if (version == ONE || version == TWO)
Should be able.

> or version(!Windows)
I wish.

> or what about...
> 
> version( ONE || !TWO)
I wish again.

> 3) can D do default values like c++? function(int num = 0)
> and you can either call function() for function(5)
Yep.  For some time now.
http://www.digitalmars.com/d/function.html

> 4) How would I convert the command #pragma warning( disable : 4800 ) to 
> D? I'm not too keen on pragmas.
In this case, I believe you'd just skip it.  There's not much reason to ignore-flag 
warnings in a compiler that ordinarily doesn't do warnings anyhow.  Although now that we 
have the -w switch maybe there should be a disable pragma...  Not sure.  I don't use -w 
all that often anyhow.

-- Chris Sauls
October 29, 2005
Re: a slew of questions about D...
On Sat, 29 Oct 2005 02:59:34 -0400, clayasaurus wrote:


> or version(!Windows)

No. You need to do ...

 version(Windows) else { } 

> 
> or what about...
> 
> version( ONE || !TWO)

No. You need to do ...

 version(ONE) version = X
 version(TWO) version = X
 version(X) { . . . }



-- 
Derek Parnell
Melbourne, Australia
29/10/2005 9:49:38 PM
October 29, 2005
Re: a slew of questions about D...
In article <98m793lpudd4$.1xzi56dp4vb37$.dlg@40tude.net>, Derek Parnell says...
>
>On Sat, 29 Oct 2005 02:59:34 -0400, clayasaurus wrote:
>
> 
>> or version(!Windows)
>
>No. You need to do ...
>
>  version(Windows) else { } 
>
>> 
>> or what about...
>> 
>> version( ONE || !TWO)
>
>No. You need to do ...
>
>  version(ONE) version = X
>  version(TWO) version = X
>  version(X) { . . . }

Actually it looks like he's trying to do "! TWO", so I'd use an else:

version(ONE) version = X;
version(TWO) {} else version = X;
version(X) { . . . }

Even uglier more verbose, but I think it'll work.

jcc7
October 29, 2005
Re: a slew of questions about D...
Derek Parnell wrote:
> On Sat, 29 Oct 2005 02:59:34 -0400, clayasaurus wrote:
> 
>  
> 
>>or version(!Windows)
> 
> 
> No. You need to do ...
> 
>   version(Windows) else { } 

Oh ok. Seems like a bit of a hack though. Imagine if I wanted to do

version(!Windows)
{
}
else
{
}

Then I'm forced to do something like...
version = TRUE

version(Windows)
{
}
else version(TRUE) // version !Windows
{
}
else
{
}

Unless there is another way around?

> 
> 
>>or what about...
>>
>>version( ONE || !TWO)
> 
> 
> No. You need to do ...
> 
>   version(ONE) version = X
>   version(TWO) version = X
>   version(X) { . . . }
>  
> 
> 

I don't mind this as much as the !version hack.

Thanks.

~ Clay
October 29, 2005
Re: a slew of questions about D...
Chris Sauls wrote:
> clayasaurus wrote:
> 
>> 1) can you do ... int function(const value) in D? or function(int 
>> value) const?
> 
> Technically (as I understand it) no.  Although it may not be /as/ 
> neccessary.
> 
>> 2) can you do versioning like...
>>
>> static if (version == ONE || version == TWO)
> 
> Should be able.
> 

I wasn't able to do so, so I just used Derek's suggestion.

>> or version(!Windows)
> 
> I wish.
> 
>> or what about...
>>
>> version( ONE || !TWO)
> 
> I wish again.
> 
>> 3) can D do default values like c++? function(int num = 0)
>> and you can either call function() for function(5)
> 
> Yep.  For some time now.
> http://www.digitalmars.com/d/function.html

Cool.

> 
>> 4) How would I convert the command #pragma warning( disable : 4800 ) 
>> to D? I'm not too keen on pragmas.
> 
> In this case, I believe you'd just skip it.  There's not much reason to 
> ignore-flag warnings in a compiler that ordinarily doesn't do warnings 
> anyhow.  Although now that we have the -w switch maybe there should be a 
> disable pragma...  Not sure.  I don't use -w all that often anyhow.

Yea, i'll just ignore it I guess. It is not so important in the scheme 
of things.

> 
> -- Chris Sauls

Thanks

~ Clay
October 29, 2005
Re: a slew of questions about D...
J C Calvarese wrote:
> In article <98m793lpudd4$.1xzi56dp4vb37$.dlg@40tude.net>, Derek Parnell says...
> 
>>On Sat, 29 Oct 2005 02:59:34 -0400, clayasaurus wrote:
>>
>>
>>
>>>or version(!Windows)
>>
>>No. You need to do ...
>>
>> version(Windows) else { } 
>>
>>
>>>or what about...
>>>
>>>version( ONE || !TWO)
>>
>>No. You need to do ...
>>
>> version(ONE) version = X
>> version(TWO) version = X
>> version(X) { . . . }
> 
> 
> Actually it looks like he's trying to do "! TWO", so I'd use an else:
> 
> version(ONE) version = X;
> version(TWO) {} else version = X;
> version(X) { . . . }
> 
> Even uglier more verbose, but I think it'll work.
> 
> jcc7

Yup. :-P Adding a simple ! to the version would make things much better, 
&& and || would be nice too, but I'm not sure how diffuclt these things 
would be to implement. I can live with 'else' for now.

Thanks

~ Clay
October 30, 2005
Re: a slew of questions about D...
I have another quick question...

does D have the c++ equivilent of #pragma pack(push,1), is it not needed 
with D, or just not implemented.

In the C++ code it is implemented like...

#pragma pack(push,1)

#pragma pack(1)

struct
{
  a, b, c;
}

#pragma pack(1)

struct
{
  ...
}

#pragma(pop, 1)

Can I get the D equivilent just by using the align attribute? Thanks.

~ Clay
October 30, 2005
Re: a slew of questions about D...
"clayasaurus" <clayasaurus@gmail.com> wrote in message 
news:dk3cit$klj$1@digitaldaemon.com...
> does D have the c++ equivilent of #pragma pack(push,1), is it not needed 
> with D, or just not implemented.
> Can I get the D equivilent just by using the align attribute? Thanks.

It's mostly not needed because of the better alignment support in D.  In 
C++, the pack push and pop operations are needed because normally member 
alignment is controlled by a command-line switch, so the pushing and popping 
is so that changing the alignment for one struct doesn't change it for all 
the rest.  But in D, to change the alignment for one struct, you just use 
the very obvious syntax:

align(1) struct Something
{
   ...
}

And the alignment will stay the same (i.e. the default, or whatever you set 
them to) on all the other structs in your program.
October 31, 2005
Re: a slew of questions about D...
Ah, that explains it. Thanks : )

~ Clay

Jarrett Billingsley wrote:
> "clayasaurus" <clayasaurus@gmail.com> wrote in message 
> news:dk3cit$klj$1@digitaldaemon.com...
> 
>>does D have the c++ equivilent of #pragma pack(push,1), is it not needed 
>>with D, or just not implemented.
>>Can I get the D equivilent just by using the align attribute? Thanks.
> 
> 
> It's mostly not needed because of the better alignment support in D.  In 
> C++, the pack push and pop operations are needed because normally member 
> alignment is controlled by a command-line switch, so the pushing and popping 
> is so that changing the alignment for one struct doesn't change it for all 
> the rest.  But in D, to change the alignment for one struct, you just use 
> the very obvious syntax:
> 
> align(1) struct Something
> {
>     ...
> }
> 
> And the alignment will stay the same (i.e. the default, or whatever you set 
> them to) on all the other structs in your program. 
> 
>
« First   ‹ Prev
1 2 3
Top | Discussion index | About this forum | D home