M
Gary James wrote:
>
> On Sun, 17 Jun 2001 00:28:15 Jiri Baum wrote:
>
> > Ok, according to Sarah, you can do it the simple way:
> > typedef f32 (*plc_get_f_func_t)(plc_pt_t p);
> > return ((plc_get_f_func_t) plc_get)(p);
> >
> > or the difficult way:
> > return ( (f32(*)(plc_pt_t))plc_get )(p);
> >
> >
> > I prefer the second one, because the first is not all that simpler and
> > the second at least looks neat
> >
>
> I've kinda lost track of what this thread is trying to accomplish. It seems
> like we are going off on a tangent to save literaly a couple cycles, and in
> the end creating something that is not easy to understand. If you really
> care that much about a couple cycles, then you should be programming in
> assembly language not C (imho).
>
> Why wouldn't you make the normal plc_get() just return a union type.
>
> typedef union
> {
> unsigned char v_8;
> unsigned short v_16;
> unsigned long v_32;
> float v_f;
> } ANY_TYPE;
>
> ANY_TYPE x;
>
> ANY_TYPE plc_get (void)
> {
> return x;
> }
>
> int main (void)
> {
> ANY_TYPE y;
>
> x.v_32 = 100;
> y = plc_get();
> printf ("%u %u %u\n", y.v_8, y.v_16, y.v_32);
>
> x.v_f = 33.5;
> y = plc_get();
> printf ("%f\n", y.v_f);
>
> return 0;
> }
Gary has a point! Thanks!
Is anybody against this?
Cheers,
Mario.
----------------------------------------------------------------------------
Mario J. R. de Sousa
[email protected]
----------------------------------------------------------------------------
The box said it requires Windows 95 or better, so I installed Linux
_______________________________________________
LinuxPLC mailing list
[email protected]
http://linuxplc.org/mailman/listinfo/linuxplc
>
> On Sun, 17 Jun 2001 00:28:15 Jiri Baum wrote:
>
> > Ok, according to Sarah, you can do it the simple way:
> > typedef f32 (*plc_get_f_func_t)(plc_pt_t p);
> > return ((plc_get_f_func_t) plc_get)(p);
> >
> > or the difficult way:
> > return ( (f32(*)(plc_pt_t))plc_get )(p);
> >
> >
> > I prefer the second one, because the first is not all that simpler and
> > the second at least looks neat
> >
>
> I've kinda lost track of what this thread is trying to accomplish. It seems
> like we are going off on a tangent to save literaly a couple cycles, and in
> the end creating something that is not easy to understand. If you really
> care that much about a couple cycles, then you should be programming in
> assembly language not C (imho).
>
> Why wouldn't you make the normal plc_get() just return a union type.
>
> typedef union
> {
> unsigned char v_8;
> unsigned short v_16;
> unsigned long v_32;
> float v_f;
> } ANY_TYPE;
>
> ANY_TYPE x;
>
> ANY_TYPE plc_get (void)
> {
> return x;
> }
>
> int main (void)
> {
> ANY_TYPE y;
>
> x.v_32 = 100;
> y = plc_get();
> printf ("%u %u %u\n", y.v_8, y.v_16, y.v_32);
>
> x.v_f = 33.5;
> y = plc_get();
> printf ("%f\n", y.v_f);
>
> return 0;
> }
Gary has a point! Thanks!
Is anybody against this?
Cheers,
Mario.
----------------------------------------------------------------------------
Mario J. R. de Sousa
[email protected]
----------------------------------------------------------------------------
The box said it requires Windows 95 or better, so I installed Linux
_______________________________________________
LinuxPLC mailing list
[email protected]
http://linuxplc.org/mailman/listinfo/linuxplc