Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 21, 2001 typeless consts | ||||
---|---|---|---|---|
| ||||
Feature suggestion. It would be nice if D could determine type of constant automatically, so we could write: const i = 10, d = 123.456, s = "Hello, world!" Would be great... |
December 21, 2001 Re: typeless consts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a003uc$1m0e$1@digitaldaemon.com... > Feature suggestion. It would be nice if D could determine type of constant automatically, so we could write: > > const i = 10, d = 123.456, s = "Hello, world!" > > Would be great... Actually, with string literals, the compiler does do that. But it has resulted in a lot of problems. It's much better to just say what type it is. |
December 22, 2001 Re: typeless consts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:a00e4m$1thm$1@digitaldaemon.com... > Actually, with string literals, the compiler does do that. But it has The following program doesn't compile: const i = 666; const s = "hello, world!"; > resulted in a lot of problems. It's much better to just say what type it is. Problems? |
December 22, 2001 Re: typeless consts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a01g86$2ma7$2@digitaldaemon.com... > "Walter" <walter@digitalmars.com> wrote in message news:a00e4m$1thm$1@digitaldaemon.com... > > > Actually, with string literals, the compiler does do that. But it has > > The following program doesn't compile: > > const i = 666; > const s = "hello, world!"; Yes, it won't, because while "hello, world" starts out typeless, the declaration for s needs a type. > > resulted in a lot of problems. It's much better to just say what type it > is. > > Problems? One problem, for example, is "a" a char, char[1], wchar, wchar[1]? This causes trouble with overloading. |
December 22, 2001 Re: typeless consts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:a02ebb$ajb$1@digitaldaemon.com... > Yes, it won't, because while "hello, world" starts out typeless, the declaration for s needs a type. That was exactly my proposal - make the type in const declarations unnecessary... > One problem, for example, is "a" a char, char[1], wchar, wchar[1]? This causes trouble with overloading. Whatever it suites - like a literal "a" can be a char or a char[1] depending on context. Ambiguities with overloading are easily resolved using cast(). Or, typed consts could be used in these cases. |
December 22, 2001 Re: typeless consts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | Lazy, lazy, lazy!!! Sean "Pavel Minayev" <evilone@omen.ru> wrote in message news:a003uc$1m0e$1@digitaldaemon.com... > Feature suggestion. It would be nice if D could determine type of constant automatically, so we could write: > > const i = 10, d = 123.456, s = "Hello, world!" > > Would be great... |
December 22, 2001 Re: typeless consts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a02ikb$dlr$1@digitaldaemon.com... > "Walter" <walter@digitalmars.com> wrote in message news:a02ebb$ajb$1@digitaldaemon.com... > > Yes, it won't, because while "hello, world" starts out typeless, the declaration for s needs a type. > That was exactly my proposal - make the type in const declarations unnecessary... > > One problem, for example, is "a" a char, char[1], wchar, wchar[1]? This causes trouble with overloading. > Whatever it suites - like a literal "a" can be a char or a char[1] depending on context. Ambiguities with overloading are easily resolved using cast(). Or, typed consts could be used in these cases. The language can handle a few ambiguities requiring casting like string literals. Doing it in general, like for variables, will fill the code up with ugly casting. |
Copyright © 1999-2021 by the D Language Foundation