Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Call oddities: &Test() vs &Test vs Test (http://www.velocityreviews.com/forums/t700397-call-oddities-and-test-vs-and-test-vs-test.html)

Skybuck Flying 10-04-2009 04:10 PM

Call oddities: &Test() vs &Test vs Test
 
Hello,

There are some call oddities in both languages: Delphi and C.

The purpose of a language is to tell the computer what to do... but ofcourse
a language is also for us humans to understand what is written/ment.

Therefore it would be a nobble cause to try and make the language as clearly
as possible.

I now present to you some "cases" where both languages Delphi and C fail in
this regard:

Case 1 (Delphi):

IdentifierA = IdentifierB;

From this single line of code it cannot be said if IdentifierB is a field or
a routine call yet it's still allowed to be written in Delphi. Correct
translation from Delphi to C/C++ without more information, is therefore not
possible.

Case 2 (C):

IdentifierB;

From this single line of code it cannot be said if IdentifierB is a field or
a routine yet it's still allowed to be written in C. If IdentiferB is a
routine then no call will happen, which is inconsistent with Delphi and
could lead to bugs when translating from Delphi to C/C++. Correct
translation from Delphi to C/C++ without more information, is therefore not
possible.

Case 3 (Delphi):

if (Identifier) then

From this single line of code it cannot be said if Identifier is a field or
a routine call yet it's still allowed to be written in Delphi. Correct
translation from Delphi to C/C++ without more information, is therefore not
possible.

The question is can the situation be improved ?

A possible solution could be to make the () for routine calls mandatory.

Also for acquiring a pointer to a routine the () could be mandatory.

Instead of writing:

IdentifierA = &IdentifierB;

It would become:

IdentifierA = &IdentifierB();

Which would return the address of the routine IdentifierB.

IdentifierA = &IdentifierB()();

Would return the address of the second routine which is being called by the
function pointer returned by the first routine.

(Note: Delphi does not have this functionality: Calling a returned function
pointer immediatly).

Currently the situation is reserved to acquire a pointer to a routine in C
the () must not be written:

IdentifierA = &Identifier;

The question is:

Would any functionality in C be lost if this is changed to described as
above:

IdentifierA = &Identifier();

?

Bye,
Skybuck.



Skybuck Flying 10-04-2009 06:34 PM

Re: Call oddities: &Test() vs &Test vs Test
 

"Skybuck Flying" <BloodyShame@hotmail.com> wrote in message
news:918bb$4ac8c8d9$d53372a9$18439@cache1.tilbu1.n b.home.nl...
> Hello,
>
> There are some call oddities in both languages: Delphi and C.
>
> The purpose of a language is to tell the computer what to do... but
> ofcourse a language is also for us humans to understand what is
> written/ment.
>
> Therefore it would be a nobble cause to try and make the language as
> clearly as possible.
>
> I now present to you some "cases" where both languages Delphi and C fail
> in this regard:
>
> Case 1 (Delphi):
>
> IdentifierA = IdentifierB;
>
> From this single line of code it cannot be said if IdentifierB is a field
> or a routine call yet it's still allowed to be written in Delphi. Correct
> translation from Delphi to C/C++ without more information, is therefore
> not possible.
>
> Case 2 (C):
>
> IdentifierB;
>
> From this single line of code it cannot be said if IdentifierB is a field
> or a routine yet it's still allowed to be written in C. If IdentiferB is a
> routine then no call will happen, which is inconsistent with Delphi and
> could lead to bugs when translating from Delphi to C/C++. Correct
> translation from Delphi to C/C++ without more information, is therefore
> not possible.
>
> Case 3 (Delphi):
>
> if (Identifier) then
>
> From this single line of code it cannot be said if Identifier is a field
> or a routine call yet it's still allowed to be written in Delphi. Correct
> translation from Delphi to C/C++ without more information, is therefore
> not possible.
>
> The question is can the situation be improved ?
>
> A possible solution could be to make the () for routine calls mandatory.
>
> Also for acquiring a pointer to a routine the () could be mandatory.
>
> Instead of writing:
>
> IdentifierA = &IdentifierB;
>
> It would become:
>
> IdentifierA = &IdentifierB();
>
> Which would return the address of the routine IdentifierB.
>
> IdentifierA = &IdentifierB()();
>
> Would return the address of the second routine which is being called by
> the function pointer returned by the first routine.
>
> (Note: Delphi does not have this functionality: Calling a returned
> function pointer immediatly).
>
> Currently the situation is reserved to acquire a pointer to a routine in C


Typo corrected:

Currently the situation is reversed, to acquire a pointer to a routine in C

> the () must not be written:
>
> IdentifierA = &Identifier;
>
> The question is:
>
> Would any functionality in C be lost if this is changed to described as
> above:
>
> IdentifierA = &Identifier();
>
> ?
>
> Bye,
> Skybuck.
>





All times are GMT. The time now is 04:36 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.