Jump to page: 1 2
Thread overview
DMD 0.98 release
Aug 05, 2004
Walter
Aug 05, 2004
Ivan Senji
Aug 05, 2004
Matthias Becker
Aug 05, 2004
Daniel Horn
Aug 05, 2004
pragma
scalar constructors
Aug 05, 2004
Walter
Aug 05, 2004
Matthew
Aug 06, 2004
Stewart Gordon
Aug 06, 2004
Walter
Aug 05, 2004
Russ Lewis
Aug 05, 2004
Lars Ivar Igesund
Aug 10, 2004
Stewart Gordon
August 05, 2004
Focussed on eliminating compiler hangs, gpf's and internal errors.

http://www.digitalmars.com/d/changelog.html



August 05, 2004
Why don't scalar constructors take parametars?
int* ip = new int;
*ip == 0;

int* ip = new int(5);
*ip still == 0;

int* ip = new int(5,5,"HA");
*ip still == 0;

?

"Walter" <newshound@digitalmars.com> wrote in message news:cesu05$1bmc$1@digitaldaemon.com...
> Focussed on eliminating compiler hangs, gpf's and internal errors.
>
> http://www.digitalmars.com/d/changelog.html
>
>
>


August 05, 2004
>Why don't scalar constructors take parametars?
>int* ip = new int;
>*ip == 0;
>
>int* ip = new int(5);
>*ip still == 0;
>
>int* ip = new int(5,5,"HA");
>*ip still == 0;

Well, structs don't have constructors. Scalar types seem not to have them, too.


August 05, 2004
"Ivan Senji" <ivan.senji@public.srce.hr> wrote in message news:cet2hu$1fbm$1@digitaldaemon.com...
> Why don't scalar constructors take parametars?
> int* ip = new int;
> *ip == 0;
>
> int* ip = new int(5);
> *ip still == 0;
>
> int* ip = new int(5,5,"HA");
> *ip still == 0;
>
> ?

I'm not sure what the case is for it. The reason for adding the current method is for Matthew's DTL.


August 05, 2004
Walter wrote:
> Focussed on eliminating compiler hangs, gpf's and internal errors.
> 
> http://www.digitalmars.com/d/changelog.html

The changelog doesn't include 0.98.  Otherwise, thanks much for the release!

August 05, 2004
Russ Lewis wrote:

> Walter wrote:
> 
>> Focussed on eliminating compiler hangs, gpf's and internal errors.
>>
>> http://www.digitalmars.com/d/changelog.html
> 
> 
> The changelog doesn't include 0.98.  Otherwise, thanks much for the release!
> 

Yes, it do (and it did). Maybe your browser had a problem that made it use the cache?

Lars Ivar Igesund
August 05, 2004
but you can overload OpCall for a struct and for a class to do the same thing
you cannot, however, overload OpCall for int unless I'm mistaken

so while you could make a common way to create either structs or classes , you have to specialize for all the basic types--and woe to you if you should encounter typedefs.

Matthias Becker wrote:
>>Why don't scalar constructors take parametars?
>>int* ip = new int;
>>*ip == 0;
>>
>>int* ip = new int(5);
>>*ip still == 0;
>>
>>int* ip = new int(5,5,"HA");
>>*ip still == 0;
> 
> 
> Well, structs don't have constructors. Scalar types seem not to have them, too.
> 
> 
August 05, 2004
In article <ceu40a$2355$1@digitaldaemon.com>, Daniel Horn says...
>
>but you can overload OpCall for a struct and for a class to do the same
>thing
>you cannot, however, overload OpCall for int unless I'm mistaken
>
>so while you could make a common way to create either structs or classes , you have to specialize for all the basic types--and woe to you if you should encounter typedefs.

I, too was wondering why you can't simply go "new int(42)", when its pretty much the most obvious constructor a scalar type could have (IMO).  Granted, it's pretty useless outside of templates, but it *looks* correct, right? Frustrating.

Now if global operators were overload-able, I suppose this would be the equivalent of simulating a constructor on a built-in scalar type:

# static int opCall(int value){
#     return(value);
# }

Which doesn't get us very close:

# int foo = int(42); // closer, but not close enough.

I wouldn't even begin to know how to roll a static 'new' operator for type int. Every time I try, the syntax folds up into something ambiguous. :(

Now, not to beat a dead horse, but is this something that a "typedef block" (or "extended typedef" i guess) could help solve?

# typedef int Integer{
#     this(int value){
#         this = value; //'this' is an 'int' within this particular typedef
#     }
#     this(int value,int value2,char[] msg){
#         this = value + value2;
#         writefln(msg,"[",this,"]");
#     }
# }

At least then you have something that will /cast/ to an int with no trouble at all:

# int* foo = new Integer(42);
# int* foo = new Integer(5,5,"HA");

Now what would really do the job is if we were allowed something like this in addition to the aforementioned sytnax:

# typedef .int int{ //extension of global type 'int'
#     this(.int value){
#         this = value;
#     }
# }

Any thoughts from the crowd?

- Pragma


August 05, 2004
"Walter" <newshound@digitalmars.com> wrote in message news:cettf5$1u0m$1@digitaldaemon.com...
>
> "Ivan Senji" <ivan.senji@public.srce.hr> wrote in message news:cet2hu$1fbm$1@digitaldaemon.com...
> > Why don't scalar constructors take parametars?
> > int* ip = new int;
> > *ip == 0;
> >
> > int* ip = new int(5);
> > *ip still == 0;
> >
> > int* ip = new int(5,5,"HA");
> > *ip still == 0;
> >
> > ?
>
> I'm not sure what the case is for it. The reason for adding the current method is for Matthew's DTL.

That's great, but I agree with the others that one should be able to parameterise the construction. :)

I also think structs should have ctors, but that's another issue. (Since we have faux-ctors by opCall, why not acecpt reality and give proper ctors?)



August 06, 2004
Walter wrote:

> "Ivan Senji" <ivan.senji@public.srce.hr> wrote in message
> news:cet2hu$1fbm$1@digitaldaemon.com...
> 
>> Why don't scalar constructors take parametars?
>> int* ip = new int;
>> *ip == 0;

Would I be right to figure that this is just syntactic sugar for

	int* ip = new int[1];

albeit with some generic programming advantage I'm not sure I see?

>> int* ip = new int(5);
>> *ip still == 0;
>>
>> int* ip = new int(5,5,"HA");
>> *ip still == 0;
>>
>> ?
> 
> I'm not sure what the case is for it. The reason for adding the current
> method is for Matthew's DTL.

Then what _does_ new int(5) mean at the moment?  Or is it just a bug that the compiler accepts it?

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