Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #82377

Re: Does this program have the specified behavior?

From Juha Nieminen <nospam@thanks.invalid>
Newsgroups comp.lang.c++, comp.lang.c
Subject Re: Does this program have the specified behavior?
Date 2021-11-18 06:32 +0000
Organization Aioe.org NNTP Server
Message-ID <sn4s2o$tke$1@gioia.aioe.org> (permalink)
References <TeidndjwvpeU5Qn8nZ2dnUU7-QmdnZ2d@giganews.com> <2ce7a201-45d4-49aa-a512-2ca01a4fbd36n@googlegroups.com> <L6KdnUDjcci1FAn8nZ2dnUU7-V_NnZ2d@giganews.com> <536lJ.49729$JZ3.33398@fx05.iad> <dtOdnfVlRJHziwj8nZ2dnUU7-QHNnZ2d@giganews.com>

Cross-posted to 2 groups.

Show all headers | View raw


In comp.lang.c++ olcott <NoOne@nowhere.com> wrote:
>>> typedef int (*ptr)();
>>>
>>> int H(ptr x, ptr y)
>>> {
>>>     x(y); // direct execution of P(P)
>>>     return 1;
>>> }
> 
> This code does compile and run correctly.

It might compile as C, but it shouldn't compile as C++, because it's trying
to call an int(*)() with a parameter, even though that function (that the
pointer is pointing to does not take any parameter.)

Perhaps if it were an int(*)(void*) and then you reinterpret-cast the
parameter in order to call it, then it would compile.

As for "runs correctly", I don't see how this "runs correctly". Unless you
mean an infinite recursion that does nothing "runs correctly".

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Do this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-16 21:33 -0600
  Re: Do this program have the specified behavior? wij <wyniijj@gmail.com> - 2021-11-16 20:10 -0800
    Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-16 22:46 -0600
      Re: Does this program have the specified behavior? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-11-16 21:12 -0800
        Re: Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-17 08:33 -0600
      Re: Does this program have the specified behavior? Richard Damon <Richard@Damon-Family.org> - 2021-11-17 06:53 -0500
        Re: Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-17 08:49 -0600
          Re: Does this program have the specified behavior? Juha Nieminen <nospam@thanks.invalid> - 2021-11-18 06:32 +0000
            Re: Does this program have the specified behavior? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-11-18 11:15 +0000
              Re: Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-18 08:59 -0600
            Re: Does this program have the specified behavior? olcott <NoOne@NoWhere.com> - 2021-11-18 08:58 -0600
      Re: Does this program have the specified behavior? Anurag Ranjan <anuragranjan630@gmail.com> - 2021-11-17 22:00 +0000

csiph-web