Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/11/11 09:10
Read: times


 
#184630 - not necessarily
Responding to: ???'s previous message
Oliver Sedlacek said:
OP said:
typedef struct { 
    BYTE ip_addr[4];
} IP_ADDR;

IP_ADDR broadcast_IP = {255,255,255,255};
IP_ADDR zero_ip = {0, 0, 0, 0};
IP_ADDR ip_addrr;

 


Shouldn't you have nested curly brackets, e.g.

IP_ADDR broadcast_IP = {{255,255,255,255}};
IP_ADDR zero_ip = {{0, 0, 0, 0}};
IP_ADDR ip_addrr;
 

I was going to answer the same, but then went out to study C99 once again, and turns out, no, you don't *need* that (although it's certainly a good idea).
C99, 6.7.8#20 said:
If the aggregate or union contains elements or members that are aggregates or unions,
these rules apply recursively to the subaggregates or contained unions. If the initializer of
asubaggregate or contained union begins with a left brace, the initializers enclosed by
that brace and its matching right brace initialize the elements or members of the
subaggregate or the contained union. Otherwise, only enough initializers from the list are
taken to account for the elements or members of the subaggregate or the first member of
the contained union; anyremaining initializers are left to initialize the next element or
member of the aggregate of which the current subaggregate or contained union is a part.


JW



List of 39 messages in thread
TopicAuthorDate
Keil problem...            01/01/70 00:00      
   Kel support            01/01/70 00:00      
      Keil support            01/01/70 00:00      
         Reward for finding bug            01/01/70 00:00      
            been tried            01/01/70 00:00      
               public bug tracker            01/01/70 00:00      
                  It's not a KEIL-specific problem ...            01/01/70 00:00      
                     not really            01/01/70 00:00      
                        It's those "snapshots" that I meant            01/01/70 00:00      
                           Not true            01/01/70 00:00      
                              Remember, where you sit determines what you see            01/01/70 00:00      
                                 Concept            01/01/70 00:00      
                                 I do not ...            01/01/70 00:00      
                                    Comfort contra mobile phone            01/01/70 00:00      
                                       Where you sit determines what you see ...            01/01/70 00:00      
                                          You are still assuming you know what other people think/do            01/01/70 00:00      
                                             You've overlooked the most basic fact ...            01/01/70 00:00      
                                                Unuseful toy?            01/01/70 00:00      
                                                   Once again, you've missed the point ...            01/01/70 00:00      
                                                      Look for progress, instead of just looking back at history            01/01/70 00:00      
                                                         are you that lucky?            01/01/70 00:00      
                                                            Yes            01/01/70 00:00      
                                                         Consider my position            01/01/70 00:00      
      keil update            01/01/70 00:00      
         auto variables            01/01/70 00:00      
   Global Variable Initiaization            01/01/70 00:00      
   just curious            01/01/70 00:00      
      Always good to hide black-box data in structs            01/01/70 00:00      
      Initialising array inside struct            01/01/70 00:00      
         not necessarily            01/01/70 00:00      
      Library            01/01/70 00:00      
   New facts...            01/01/70 00:00      
      At the very least use static for one-time initialized locals            01/01/70 00:00      
         it works! thanks...            01/01/70 00:00      
            Look at code in Debugger. It will tell all.            01/01/70 00:00      
               It's called "Overlaying"            01/01/70 00:00      
                  Optimization            01/01/70 00:00      
      are you sure ...            01/01/70 00:00      
   Thanks...            01/01/70 00:00      

Back to Subject List