Re: Can someone please verify the execution trace of this?

Liste des GroupesRevenir à cl c++ 
Sujet : Re: Can someone please verify the execution trace of this?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c++
Date : 21. May 2024, 04:31:37
Autres entêtes
Organisation : None to speak of
Message-ID : <87r0dvki9i.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
wij <wyniijj5@gmail.com> writes:
[...]
typedef int (*ptr)();  // ptr is pointer to int function
int H(ptr x, ptr y);
int D(ptr x)
{
  int Halt_Status = H(x, x);
  if (Halt_Status)
    HERE: goto HERE;
  return Halt_Status;
}
>
int main()
{
  H(D,D);
  return 0;
}
>
The code above does not compile:
>
Yes, it does (as you acknowledge in a later post).
>
This:
    typedef int (*ptr)();
defines "ptr" as an alias for a type that can be described in English
as "pointer to function returning int".  The empty parentheses
indicate that the function takes an unspecified but fixed number
and type(s) of arguments; this is an old-style declaration.
>
(The C23 standard, not yet released, changes the semantics of empty
parentheses, causing the code to be invalid, but let's assume C17.)
>
The function H is declared but not defined.  That doesn't prevent
the code from being *compiled*, but it does prevent it from being
*linked* to produce an executable program.  Perhaps a definition
of H has been presented in some other article, but I will not waste
my time hunting for it.
>
Ignoring variadic functions like printf, every function call
must pass the appropriate number and types of arguments, matching
the parameters defined by the corresponding function definition.
(In some cases there can be implicit type conversions, but there
are no implicit conversions for arguments or parameters of function
pointer type.)  If a correct *prototype* (a function declaration that
specifies the types of all parameters) is visible, this is enforced
at compile time; failing to do so is a *constraint violation*,
requiring a compile-time diagnostic.  If no such prototype is
visible, violations of this rule need not be diagnosed, but result
in *undefined behavior*; the C standard says nothing about what
the program will do.
>
I'll note that the code (declares and) defines the function D,
but never calls it.  The address of D is passed to H, but without
a definition of H we can't guess what it does with that address.
>
It's possible to rewrite the code to (a) avoid the use of old-style
function declarations and (b) avoids any undefined behavior --
but without knowing or being able to guess just what the program
is supposed to do, I see no point in doing so.
>
The main point is this: The function H is declared but never
defined, so it's impossible to create a running program from this
code, and impossible to guess what it's intended to do without more
information.  I will not make any assumptions about how H is meant
to be defined or consult other posts to find a definition.  I may or
may not follow this thread to see if any clarifications are posted.
>
The code as presented is a valid C *translation unit*, but it is
not a valid *program*, and it has no behavior.

My apologies, I did not notice this had been posted to comp.lang.c++
until just as I posted my followup.  If I had noticed that, I probably
wouldn't have posted at all.  I'll try to pay better attention.

C++ does not have old-style function declaration.  Empty parentheses
in a C++ function declaration or definition indicate that the
function has no parameters.  In C++, a pointer of type "ptr" can
only point to a function with no parameters.  The call "H(D, D)"
passes the address of the function D (which has one parameter) to
a parameter of type "ptr" (which requires a pointer to a function
with no parameters).  That's an error.

The code is ill-formed in C++.  And of course the lack of any
definition of H is another problem that makes it difficult or
impossible to correct the C++ errors and produce a valid program.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
18 May 24 * Can someone please verify the execution trace of this?136olcott
19 May 24 +- Re: Can someone please verify the execution trace of this?1Richard Damon
19 May 24 +* Re: Can someone please verify the execution trace of this?3Sam
19 May 24 i`* Re: Can someone please verify the execution trace of this?2olcott
19 May 24 i `- Re: Can someone please verify the execution trace of this?1jak
19 May 24 +* Re: Can someone please verify the execution trace of this?128Bonita Montero
19 May 24 i`* Re: Can someone please verify the execution trace of this?127olcott
19 May 24 i +- Re: Can someone please verify the execution trace of this?1Richard Damon
20 May 24 i `* Re: Can someone please verify the execution trace of this?125Bonita Montero
20 May 24 i  `* Re: Can someone please verify the execution trace of this?124olcott
20 May 24 i   +* Re: Can someone please verify the execution trace of this?54Bonita Montero
20 May 24 i   i`* Re: Can someone please verify the execution trace of this?53olcott
20 May 24 i   i +* Re: Can someone please verify the execution trace of this?44Bonita Montero
20 May 24 i   i i`* Re: Can someone please verify the execution trace of this?43olcott
20 May 24 i   i i `* Re: Can someone please verify the execution trace of this?42Bonita Montero
20 May 24 i   i i  `* Re: Can someone please verify the execution trace of this?41olcott
20 May 24 i   i i   `* Re: Can someone please verify the execution trace of this?40Bonita Montero
20 May 24 i   i i    `* Re: Can someone please verify the execution trace of this?39olcott
20 May 24 i   i i     +* Re: Can someone please verify the execution trace of this?2Richard Harnden
20 May 24 i   i i     i`- Re: Can someone please verify the execution trace of this?1olcott
20 May 24 i   i i     `* Re: Can someone please verify the execution trace of this?36Chris M. Thomasson
20 May 24 i   i i      `* Re: Can someone please verify the execution trace of this?35olcott
20 May 24 i   i i       `* Re: Can someone please verify the execution trace of this?34Chris M. Thomasson
20 May 24 i   i i        +* Re: Can someone please verify the execution trace of this?13olcott
20 May 24 i   i i        i`* Re: Can someone please verify the execution trace of this?12Chris M. Thomasson
20 May 24 i   i i        i `* Re: Can someone please verify the execution trace of this?11olcott
20 May 24 i   i i        i  +- Re: Can someone please verify the execution trace of this?1Chris M. Thomasson
20 May 24 i   i i        i  +* Re: Can someone please verify the execution trace of this?3Chris M. Thomasson
20 May 24 i   i i        i  i`* Re: Can someone please verify the execution trace of this?2olcott
20 May 24 i   i i        i  i `- Re: Can someone please verify the execution trace of this?1Chris M. Thomasson
20 May 24 i   i i        i  `* Re: Can someone please verify the execution trace of this?6Chris M. Thomasson
20 May 24 i   i i        i   `* Re: Can someone please verify the execution trace of this?5olcott
20 May 24 i   i i        i    `* Re: Can someone please verify the execution trace of this?4Chris M. Thomasson
20 May 24 i   i i        i     `* Re: Can someone please verify the execution trace of this?3olcott
20 May 24 i   i i        i      `* Re: Can someone please verify the execution trace of this?2Chris M. Thomasson
20 May 24 i   i i        i       `- Re: Can someone please verify the execution trace of this?1Chris M. Thomasson
20 May 24 i   i i        `* Re: Can someone please verify the execution trace of this?20Chris M. Thomasson
20 May 24 i   i i         `* Re: Can someone please verify the execution trace of this?19olcott
20 May 24 i   i i          `* Re: Can someone please verify the execution trace of this?18Chris M. Thomasson
20 May 24 i   i i           `* Re: Can someone please verify the execution trace of this?17olcott
20 May 24 i   i i            `* Re: Can someone please verify the execution trace of this?16Chris M. Thomasson
20 May 24 i   i i             `* Re: Can someone please verify the execution trace of this?15olcott
20 May 24 i   i i              `* Re: Can someone please verify the execution trace of this?14Chris M. Thomasson
20 May 24 i   i i               `* Re: Can someone please verify the execution trace of this?13olcott
20 May 24 i   i i                `* Re: Can someone please verify the execution trace of this?12Chris M. Thomasson
20 May 24 i   i i                 +- Re: Can someone please verify the execution trace of this?1Chris M. Thomasson
20 May 24 i   i i                 `* Re: Can someone please verify the execution trace of this?10olcott
20 May 24 i   i i                  `* Re: Can someone please verify the execution trace of this?9Chris M. Thomasson
20 May 24 i   i i                   `* Re: Can someone please verify the execution trace of this?8Chris M. Thomasson
20 May 24 i   i i                    `* Re: Can someone please verify the execution trace of this?7olcott
20 May 24 i   i i                     +* Re: Can someone please verify the execution trace of this?5Chris M. Thomasson
20 May 24 i   i i                     i`* Re: Can someone please verify the execution trace of this?4olcott
20 May 24 i   i i                     i `* Re: Can someone please verify the execution trace of this?3Chris M. Thomasson
20 May 24 i   i i                     i  +- Re: Can someone please verify the execution trace of this?1Chris M. Thomasson
20 May 24 i   i i                     i  `- Re: Can someone please verify the execution trace of this?1olcott
20 May 24 i   i i                     `- Re: Can someone please verify the execution trace of this?1Chris M. Thomasson
20 May 24 i   i `* Re: Can someone please verify the execution trace of this?8Fred. Zwarts
20 May 24 i   i  `* Re: Can someone please verify the execution trace of this?7olcott
20 May 24 i   i   +* Re: Can someone please verify the execution trace of this?2Paavo Helde
20 May 24 i   i   i`- Re: Can someone please verify the execution trace of this?1olcott
20 May 24 i   i   `* Re: Can someone please verify the execution trace of this?4Bonita Montero
20 May 24 i   i    `* Re: Can someone please verify the execution trace of this?3olcott
21 May 24 i   i     `* Re: Can someone please verify the execution trace of this?2Fred. Zwarts
21 May 24 i   i      `- Re: Can someone please verify the execution trace of this?1olcott
20 May 24 i   +* Re: Can someone please verify the execution trace of this?37wij
20 May 24 i   i+* Re: Can someone please verify the execution trace of this?5olcott
20 May 24 i   ii`* Re: Can someone please verify the execution trace of this?4wij
20 May 24 i   ii `* Re: Can someone please verify the execution trace of this?3olcott
20 May 24 i   ii  `* Re: Can someone please verify the execution trace of this?2wij
20 May 24 i   ii   `- Re: Can someone please verify the execution trace of this?1olcott
21 May 24 i   i`* Re: Can someone please verify the execution trace of this?31Keith Thompson
21 May 24 i   i +- Re: Can someone please verify the execution trace of this?1Keith Thompson
21 May 24 i   i `* Re: Can someone please verify the execution trace of this?29olcott
21 May 24 i   i  +- Re: Can someone please verify the execution trace of this?1Fred. Zwarts
21 May 24 i   i  `* Re: Can someone please verify the execution trace of this?27Janis Papanagnou
21 May 24 i   i   `* Re: Can someone please verify the execution trace of this?26olcott
21 May 24 i   i    `* Re: Can someone please verify the execution trace of this?25Bonita Montero
21 May 24 i   i     `* Can D correctly simulated by H reach its own line 06 and halt?24olcott
21 May 24 i   i      `* Re: Can D correctly simulated by H reach its own line 06 and halt?23Bonita Montero
21 May 24 i   i       `* Re: Can D correctly simulated by H reach its own line 06 and halt?22olcott
21 May 24 i   i        `* Re: Can D correctly simulated by H reach its own line 06 and halt?21Bonita Montero
21 May 24 i   i         `* Re: Can D correctly simulated by H reach its own line 06 and halt?20olcott
21 May 24 i   i          `* Re: Can D correctly simulated by H reach its own line 06 and halt?19Bonita Montero
21 May 24 i   i           `* Re: Can D correctly simulated by H reach its own line 06 and halt?18olcott
22 May 24 i   i            +* Re: Can D correctly simulated by H reach its own line 06 and halt?7Bonita Montero
22 May 24 i   i            i`* Re: Can D correctly simulated by H reach its own line 06 and halt?6olcott
22 May 24 i   i            i `* Re: Can D correctly simulated by H reach its own line 06 and halt?5Bonita Montero
22 May 24 i   i            i  `* Re: Can D correctly simulated by H reach its own line 06 and halt?4olcott
22 May 24 i   i            i   `* Re: Can D correctly simulated by H reach its own line 06 and halt?3Bonita Montero
22 May 24 i   i            i    `* Re: Can D correctly simulated by H reach its own line 06 and halt?2olcott
22 May 24 i   i            i     `- Re: Can D correctly simulated by H reach its own line 06 and halt?1Bonita Montero
22 May 24 i   i            `* D correctly simulated by H remains stuck in recursive simulation10olcott
22 May 24 i   i             +* Re: D correctly simulated by H remains stuck in recursive simulation8wij
22 May 24 i   i             i+* Re: D correctly simulated by H remains stuck in recursive simulation [good attempt]3olcott
22 May 24 i   i             ii`* Re: D correctly simulated by H remains stuck in recursive simulation [good attempt]2olcott
22 May 24 i   i             ii `- Re: D correctly simulated by H remains stuck in recursive simulation [good attempt]1wij
22 May 24 i   i             i`* Re: D correctly simulated by H remains stuck in recursive simulation4olcott
23 May 24 i   i             i `* Re: D correctly simulated by H remains stuck in recursive simulation3Chris M. Thomasson
23 May 24 i   i             i  `* Re: D correctly simulated by H remains stuck in recursive simulation2olcott
23 May 24 i   i             i   `- Re: D correctly simulated by H remains stuck in recursive simulation1Chris M. Thomasson
22 May 24 i   i             `- Re: D correctly simulated by H remains stuck in recursive simulation1Fred. Zwarts
21 May 24 i   `* Re: Can someone please verify the execution trace of this?32Sam
20 May 24 `* Re: Can someone please verify the execution trace of this?3Marcel Mueller

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal