Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
January 03, 2004 let the implementation be the definition | ||||
---|---|---|---|---|
| ||||
admittedly, im green around the gills when it comes to a language such as D, but i have a complaint/question/suggestion... Why must functions and such be declared twice? It is my understanding that the predeclared function is to serve as a prototype for the compiler to do type checking and make sure that the calling is correct. I dont understand why this is needed as the actual function itself could easily serve as the prototype for itself, IMHO. Could someone be kind enough to explain why this is needed? and why it isnt possible to make the function implemtation also its declaration. |
January 03, 2004 Re: let the implementation be the definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lewis | "Lewis" <dethbomb@hotmail.com> wrote in message news:bt5t92$2dr1$1@digitaldaemon.com... > admittedly, im green around the gills when it comes to a language such as D, but > i have a complaint/question/suggestion... > > Why must functions and such be declared twice? Why indeed. They don't in D <g>. > It is my understanding that the predeclared function is to serve as a prototype > for the compiler to do type checking and make sure that the calling is correct. > I dont understand why this is needed as the actual function itself could easily > serve as the prototype for itself, IMHO. > > Could someone be kind enough to explain why this is needed? and why it isnt > possible to make the function implemtation also its declaration. It's needed in C and C++ because the semantics of the language are compile-as-you-go one pass through the file. That design was appropriate for machines with little memory. D, on the other hand, does multiple passes over the code, so forward declarations are not needed. Machines have much more memory now, so the old compromises are unnecessary. Ironically, compiling C++ these days requires a great deal of memory, even though it remains a one pass semantic language. |
January 07, 2004 Re: let the implementation be the definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> "Lewis" <dethbomb@hotmail.com> wrote in message
> news:bt5t92$2dr1$1@digitaldaemon.com...
>
>>admittedly, im green around the gills when it comes to a language such as
>
> D, but
>
>>i have a complaint/question/suggestion...
>>
>>Why must functions and such be declared twice?
>
>
> Why indeed. They don't in D <g>.
>
>
>>It is my understanding that the predeclared function is to serve as a
>
> prototype
>
>>for the compiler to do type checking and make sure that the calling is
>
> correct.
>
>>I dont understand why this is needed as the actual function itself could
>
> easily
>
>>serve as the prototype for itself, IMHO.
>>
>>Could someone be kind enough to explain why this is needed? and why it
>
> isnt
>
>>possible to make the function implemtation also its declaration.
>
>
> It's needed in C and C++ because the semantics of the language are
> compile-as-you-go one pass through the file. That design was appropriate for
> machines with little memory. D, on the other hand, does multiple passes over
> the code, so forward declarations are not needed. Machines have much more
> memory now, so the old compromises are unnecessary.
>
> Ironically, compiling C++ these days requires a great deal of memory, even
> though it remains a one pass semantic language.
>
>
thanks for the reply walter
i guess im at a loss *still* when it comes to how 'import' works...
it is my belief that when i type import std.c.string; that all the functions within that file should then be available in the current module as if i had pasted the code into that module (i think)
Ive spent two weeks messing with things trying to figure out how to make functions i have in another module work in the current module, it keeps giving me a undeclared error as in:
Error 42: Symbol Undefined _Left@12 //a Left() function i coded in another module
Ive added all my modules to the command line, imported all modules, and every other thing i can think of and it still wont recognize when i use a function from another module in my current module. -sigh
If someone is willing to help i could paste some code that im using from each module and to help me get the command line i need to make it compile...
frustrated newbie :)
Lewis
|
January 07, 2004 Re: let the implementation be the definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lewis | Lewis wrote:
> i guess im at a loss *still* when it comes to how 'import' works...
> it is my belief that when i type import std.c.string; that all the functions within that file should then be available in the current module as if i had pasted the code into that module (i think)
>
> Ive spent two weeks messing with things trying to figure out how to make functions i have in another module work in the current module, it keeps giving me a undeclared error as in:
> Error 42: Symbol Undefined _Left@12 //a Left() function i coded in another module
> Ive added all my modules to the command line, imported all modules, and every other thing i can think of and it still wont recognize when i use a function from another module in my current module. -sigh
>
> If someone is willing to help i could paste some code that im using from each module and to help me get the command line i need to make it compile...
>
> frustrated newbie :)
> Lewis
a.d:
import b;
int main()
{
B();
return 0;
}
b.d:
void B() {
printf("B!\n");
}
Then, at the command line:
D:\temp\dstuff>dmd a.d b.d
D:\temp\dstuff>a
B!
-- andy
|
January 07, 2004 Re: let the implementation be the definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | Andy Friesen wrote:
> Lewis wrote:
>
>> i guess im at a loss *still* when it comes to how 'import' works...
>> it is my belief that when i type import std.c.string; that all the functions within that file should then be available in the current module as if i had pasted the code into that module (i think)
>>
>> Ive spent two weeks messing with things trying to figure out how to make functions i have in another module work in the current module, it keeps giving me a undeclared error as in:
>> Error 42: Symbol Undefined _Left@12 //a Left() function i coded in another module
>> Ive added all my modules to the command line, imported all modules, and every other thing i can think of and it still wont recognize when i use a function from another module in my current module. -sigh
>>
>> If someone is willing to help i could paste some code that im using from each module and to help me get the command line i need to make it compile...
>>
>> frustrated newbie :)
>> Lewis
>
>
> a.d:
> import b;
>
> int main()
> {
> B();
>
> return 0;
> }
>
> b.d:
> void B() {
> printf("B!\n");
> }
>
> Then, at the command line:
> D:\temp\dstuff>dmd a.d b.d
>
> D:\temp\dstuff>a
> B!
>
>
> -- andy
thanks andy,
that seems to be what im doing (similar to what someone else mentioned before), i must be not including the modules correctly in my commandline somewhere... off to try again :)
regards
Lewis
|
January 07, 2004 Re: let the implementation be the definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lewis | inline
Lewis wrote:
> Andy Friesen wrote:
>
>> Lewis wrote:
>>
>>> i guess im at a loss *still* when it comes to how 'import' works...
>>> it is my belief that when i type import std.c.string; that all the functions within that file should then be available in the current module as if i had pasted the code into that module (i think)
>>>
>>> Ive spent two weeks messing with things trying to figure out how to make functions i have in another module work in the current module, it keeps giving me a undeclared error as in:
>>> Error 42: Symbol Undefined _Left@12 //a Left() function i coded in another module
>>> Ive added all my modules to the command line, imported all modules, and every other thing i can think of and it still wont recognize when i use a function from another module in my current module. -sigh
>>>
>>> If someone is willing to help i could paste some code that im using from each module and to help me get the command line i need to make it compile...
>>>
>>> frustrated newbie :)
>>> Lewis
>>
>>
>>
>> a.d:
>> import b;
>>
>> int main()
>> {
>> B();
>>
>> return 0;
>> }
>>
>> b.d:
>> void B() {
>> printf("B!\n");
>> }
>>
>> Then, at the command line:
>> D:\temp\dstuff>dmd a.d b.d
>>
>> D:\temp\dstuff>a
>> B!
>>
>>
>> -- andy
>
>
> thanks andy,
> that seems to be what im doing (similar to what someone else mentioned before), i must be not including the modules correctly in my commandline somewhere... off to try again :)
>
> regards
> Lewis
If you haven't solved the problem (and for other problems), it would be helpful if you sent an example, with either you make file or the command line entry your using. That way we'll be able to solve your problem much more quickly. Two weeks? You should of posted sooner <g>
Anderson
|
January 10, 2004 Re: let the implementation be the definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lewis | "Lewis" <dethbomb@hotmail.com> wrote in message news:bthmng$2i94$1@digitaldaemon.com... > Error 42: Symbol Undefined _Left@12 //a Left() function i coded in another module That's coming from the linker. It means (most likely) that the module defining Left() is missing from the command to the linker. |
Copyright © 1999-2021 by the D Language Foundation