Click here to Skip to main content
15,893,923 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I working on low level C functions so i find a lot of code complex . Can someone explain me this piece of code?

if (req.pib_attr == ZB_PHY_PIB_CURRENT_CHANNEL)


zb_mlme_get_request_t req;


CSS
typedef struct zb_mlme_get_request_s
{
  zb_mac_pib_attr_t  pib_attr;
  zb_uint8_t          pib_index;
} ZB_PACKED_STRUCT
zb_mlme_get_request_t;



C#
typedef enum
{
  /* PHY PIB */
  ZB_PHY_PIB_CURRENT_CHANNEL                    = 0x00,
  ZB_PHY_PIB_CURRENT_PAGE                       = 0x04,
  /* MAC PIB */
  ZB_PIB_ATTRIBUTE_ACK_WAIT_DURATION            = 0x40,
  ZB_PIB_ATTRIBUTE_ASSOCIATION_PERMIT           = 0x41,
  ZB_PIB_ATTRIBUTE_AUTO_REQUEST                 = 0x42,
  ZB_PIB_ATTRIBUTE_BATT_LIFE_EXT                = 0x43,
  ZB_PIB_ATTRIBUTE_BATT_LIFE_EXT_PERIODS        = 0x44,
  ZB_PIB_ATTRIBUTE_BEACON_PAYLOAD               = 0x45,
  ZB_PIB_ATTRIBUTE_BEACON_PAYLOAD_LENGTH        = 0x46,
  ZB_PIB_ATTRIBUTE_BEACON_ORDER                 = 0x47,
  ZB_PIB_ATTRIBUTE_BEACON_TX_TIME               = 0x48,
  ZB_PIB_ATTRIBUTE_BSN                          = 0x49,
  ZB_PIB_ATTRIBUTE_COORD_EXTEND_ADDRESS         = 0x4a,
  ZB_PIB_ATTRIBUTE_COORD_SHORT_ADDRESS          = 0x4b,
  ZB_PIB_ATTRIBUTE_DSN                          = 0x4c,
  ZB_PIB_ATTRIBUTE_TIMESTAMP_SUPPORTED          = 0x5c,
  ZB_PIB_ATTRIBUTE_SECURITY_ENABLED             = 0x5d
} zb_mac_pib_attr_t;



Here enum is nested inside a structure .

If condition is checked here total enum variable req.pibattr is checked against a member of enum. I have checked values are not assigned to
req.pib_attr
..

How the condition will be executed .
Posted
Comments
Sergey Alexandrovich Kryukov 26-Dec-12 12:43pm    
This is not a good question. Why asking about something you did not write?

You are coming to the problem from wrong side. Why reading someone's code is you don't understand it? Learn the language first, write your own code instead, for exercise. When you are done, look at someone's code again. By the way, one simple advice: start from reading the whole manual at once in one single block. Even if you would not understand everything, you will get a good idea on what's involved.
—SA

Hi

If you want to learn how enum work in c#, you can check this Example
 
Share this answer
 
The comparison will compare the value in the variable req.pib_attr to the value of ZB_PHY_PIB_CURRENT_CHANNEL which is 0...

It is not much different than comparing a variable with a constant.

C++
int a = 5;
if (a == 7) { ... }
 
Share this answer
 
Hi,

I think this link will help you.

Enum[^]
 
Share this answer
 
Comments
steven8Gerrard 26-Dec-12 9:17am    
TBH i have knowledge on ENUM and know how it works . I just haven't used enum in work . Here i just wish how if condition checks . Total enum structure will be compared against member of enum.
Andreas Gieriet 28-Dec-12 16:42pm    
You seem *not* to know what enum is: an enum is a way to define a set of symbols that each represent a specific integral number. An enum is *not* a struct. Instead of defining an enum type, one could likewise have defined each of its symbols as individual int constants.
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900