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

Discussion in 'C Programming' started by Skybuck Flying, Oct 4, 2009.

  1. 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, Oct 4, 2009
    #1
    1. Advertising

  2. "Skybuck Flying" <> wrote in message
    news:918bb$4ac8c8d9$d53372a9$1.nb.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.
    >
     
    Skybuck Flying, Oct 4, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Philip Townsend

    XPathNavigator oddities

    Philip Townsend, Dec 5, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    324
    Philip Townsend
    Dec 5, 2003
  2. =?Utf-8?B?Q2hhcmxlc0E=?=

    Datagrid 'select' button oddities

    =?Utf-8?B?Q2hhcmxlc0E=?=, Mar 20, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,860
    =?Utf-8?B?Q2hhcmxlc0E=?=
    Mar 20, 2006
  3. steve
    Replies:
    3
    Views:
    342
    steve
    Apr 14, 2004
  4. Francis Avila

    Some csv oddities

    Francis Avila, Nov 27, 2003, in forum: Python
    Replies:
    0
    Views:
    522
    Francis Avila
    Nov 27, 2003
  5. Max M
    Replies:
    4
    Views:
    324
    Tim Peters
    Jan 14, 2005
Loading...

Share This Page