Click here to Skip to main content
11,632,260 members (80,718 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C C#
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;

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;


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 26-Dec-12 3:00am
Comments
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.

int a = 5;
if (a == 7) { ... }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,

I think this link will help you.

Enum[^]
  Permalink  
Comments
steven8Gerrard at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi

If you want to learn how enum work in c#, you can check this Example
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 8,498
1 Sergey Alexandrovich Kryukov 8,149
2 Mika Wendelius 6,260
3 F-ES Sitecore 2,321
4 Suvendu Shekhar Giri 1,995


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100