Bob,

Okay, holding_cmd declared and initialized:

modbus_cmd_rd_hreg_t holding_cmd =
{
4000,  //starting register
11      //Number of registers to read (Was 10)
};

Once initialized with the braces/set notation > {...} < you can change any/all 
field(s) the way you like thenceforth with the > . < (member selection of an 
object operator), but never with > {...} < again.

holding_cmd.start_addr=4100;
holding_cmd.num_reg=10;

Global-scope variables are all initialized with 0, if no other explicit 
initializer is used.

{} (the empty set) initializes all fields of a structure with 0, even a 
structure whose fields might be arrays, whatever the scope.

So, anywhere in your program you might have: modbus_cmd_rd_hreg_t holding_cmd = 
{}; or simply holding_cmd = {}; if you may already have declared holding_cmd.

Best={1000};

Geraldo


--- In [email protected], "bobtransformer" <bobtransfor...@...> wrote:
>
> I am having a problem today...
> 
>  I can define this structure as global, above main() (or at the top of main() 
> , and use it just fine in the code...   But only once can I define it, it 
> appears, or else I get this "expected an expression" error.
> 
> 
>  modbus_cmd_rd_hreg_t   holding_cmd =
>     {
>         4000,     //starting register
>         11       //Number of registers to read (Was 10)
>     };
> 
> 
> where, modbus_cmd_rd_hreg_t itself is defined like this...
> 
> 
> 
> typedef  struct  _modbus_cmd_rd_hreg_t
> {
>     uint16_t start_addr;
>     uint16_t num_reg;
> }  modbus_cmd_rd_hreg_t;
> 
> 
> 
> OK so far and the structure gets used in the program just fine.
> 
> But when I want to re-define the values somewhere in main() so I can call the 
> function that uses this structure, like this:
> 
> 
>    holding_cmd = 
>     {                  //Error here  "expected an expression"
>         4100,
>         10
>     };
> 
> 
> I get the error on that line with the opening brace.
> 
> Any ideas ??
> 
> Thanks,
> boB
>


Reply via email to