Re: Cannot understand the following codes



* Ben C:
On 2006-03-28, Alf P. Steinbach <alfps@xxxxxxxx> wrote:
[...]

(*(void (*)
(int,t_go_measurements[]))(stGOFuncs.p_go_Measurements))(i_,ast_);

[...]

What is possibly the type of stGOFuncs.p_go_Measurements? I did not see
its definition.

It's probably a void(*)(). But not matter what type it has, the cast is undefined behavior in C++, and I believe also in C.

Why's it undefined behaviour? I can see that it invites undefined
behaviour, but not that it entails it-- if the value of
stGOFuncs.p_go_Measurements is a function of the correct type won't it
be OK?

It will be OK, /if/ the type is some pointer to function (but not if the type is simply void*, in which case it's UB); I was too hasty there.

Sorry about that... ;-)

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.



Relevant Pages

  • Re: [Lit.] Buffer overruns
    ... > Is that really undefined behavior? ... the correct type for the corresponding conversion specification, ... > output as Borland, I'm not so sure. ... but customers are what Microsoft and Borland live on. ...
    (sci.crypt)
  • Re: Arraym malloc() and free() question
    ... > If you've given a declaration with a correct return type and call it ... > with an argument of the correct type, ... > then you're not invoking undefined behavior, ... promoted type rather than the expected type. ...
    (comp.lang.c)
  • Re: [Lit.] Buffer overruns
    ... > According to Bryan Olson: ... >>Is that really undefined behavior? ... > the correct type for the corresponding conversion specification, ...
    (sci.crypt)
  • Re: what is wrong in the code?
    ... Newby on Usenet? ... answer after the message your are replying ... did you know what means 'undefined behavior'? ...
    (comp.lang.c)
  • Re: Bus Error on Integer Assignment
    ... Jeff Schwab: ... undefined behavior. ... Because it messes up the order in which people normally read text. ... What is the most annoying thing on usenet and in e-mail? ...
    (comp.lang.cpp)