EMC_TASK_SET_STATE state_msg;
There is no malloc because memory is allocated automatically then function is
entered and deallocated automatically then it exit. It is allocated stack like
and most probably on the stack but are not sure this is always the case.
Local variable I consider the best method to allocate memory then it could be
used for several reasons, usually most important because it is a local
variable. But it also have advantage memory could be allocated with increasing
pointer, this is fast and deterministic. Think ADA have a method so that
pointer to allocated memory is not remembered by misstake at compile time but
not C/C++. If you do not know what the stack is, it is a pointer to a memory
set aside this purpose, then a function is called adress before jump is stored
on stack while stack pointer is updated increased/decreased, then function exit
it is the opposite order. malloc have to find a free area while stack like
memory just increase/decrease a pointer but it only work for local variables in
functions.
Variable is initialized by row below although I are not sure all fields are
initialized. Compiler may warn if it is not initialized but as I remember it
will not warn if some fields are unitialized.
state_msg.state = EMC_TASK_STATE_ESTOP;
malloc return a pointer to "void" which is more or less equivalent to pointer
to unknown data type which must be the reason you get "no viable conversion
from int to EMC_TASK_SET_STATE" warning. You have to use type conversion to get
rid of warning (EMC_TASK_SET_STATE)malloc(...) and make sure correct size is
allocated by using sizof(...) and you also have to remember deallocate/free
memory then not used anymore but not before.
> >
> > Memory may be allocated with malloc but unless function
> > emcCommandBuffer->write(...) store the pointer internally, copy data
> > internally is below might be a much better idea. If state_msg variable is
> > not used further down or at least is not supposed the block will also limit
> > life time of variable.
> >
>
> this row of code is extract from shcom.cc:
>
> int emcCommandSend(RCS_CMD_MSG & cmd)
> {
> // write command
> if (emcCommandBuffer->write(&cmd)) {
> return -1;
> }
> emcCommandSerialNumber = cmd.serial_number;
> return 0;
> }
>
> int sendEstop()
> {
> EMC_TASK_SET_STATE state_msg;
>
> state_msg.state = EMC_TASK_STATE_ESTOP;
> emcCommandSend(state_msg);
> if (emcWaitType == EMC_WAIT_RECEIVED) {
> return emcCommandWaitReceived();
> } else if (emcWaitType == EMC_WAIT_DONE) {
> return emcCommandWaitDone();
> }
>
> return 0;
> }
>
> but there is not malloc for state_msg and not see where is initialized ....
>
> In my row code is the same situation .... but if try to use malloc obtain
> warning like "no viable conversion from int to EMC_TASK_SET_STATE" .... is
> because I try to use malloc with bad variable type?
> In my QtDro.h file I use these .hh file of Lcnc:
>
> #include "include/cmd_msg.hh"
> #include "include/stat_msg.hh"
> #include "include/emc_nml.hh"
> #include <stat_msg.hh>
> #include <cmd_msg.hh>
> #include <nml.hh>
> #include "emc.hh" // EMC NML
> #include "include/emcglb.h" // EMC_NMLFILE, TRAJ_MAX_VELOCITY,
> TOOL_TABLE_FILE
> #include "include/emccfg.h" // DEFAULT_TRAJ_MAX_VELOCITY
> #include "inifile.hh" // INIFILE
>
> Not understand how to initialize state_msg.
>
> thanks and good end of 2019 and new 2020 at all.
>
> bkt
>
> Il giorno gio 19 dic 2019 alle ore 17:54 N <[email protected]>
> ha scritto:
>
> > > just a guess.
> > >
> > > EMC_TASK_SET_STATE *state_msg;
> > >
> > > state_msg is a pointer, yet no memory allocated for it.
> > >
> > > state_msg->state = EMC_TASK_STATE_OFF;
> > >
> > > you try to write in a memory space that officially has no memory
> > assigned yet.
> > >
> > > ju
> > You are correct no memory assigned. Maybe no warning for using an
> > unitialized variable, if turned a warning would be issued for using
> > unitizialized variable.
> >
> > Memory may be allocated with malloc but unless function
> > emcCommandBuffer->write(...) store the pointer internally, copy data
> > internally is below might be a much better idea. If state_msg variable is
> > not used further down or at least is not supposed the block will also limit
> > life time of variable.
> >
> > {
> > EMC_TASK_SET_STATE state_msg;
> >
> > state_msg.state = EMC_TASK_STATE_OFF;
> > state_msg.serial_number = ++emcCommandSerialNumber;
> > emcCommandBuffer->write(&state_msg);
> > }
> >
> >
> > _______________________________________________
> > Emc-developers mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/emc-developers
> >
>
> _______________________________________________
> Emc-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/emc-developers
--
N <[email protected]>
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers