MSPLife 2 Posted July 12, 2016 Share Posted July 12, 2016 Hi everyone, I wanna understand about how the source can define as below while I can not find in any C tutorial about defining a struct. struct Element{ uint8_t *inputPxselRegister; // PinOsc: port selection address uint8_t *inputPxsel2Register; // PinOsc: port selection 2 address uint8_t *inputPxoutRegister; // PinOsc: port output address uint8_t *inputPxdirRegister; // PinOsc: port direction address uint16_t inputBits; // PinOsc: bit definition uint16_t *baseCnt; // PinOsc: base count uint16_t *threshold; }; //a dot '.' make me confuse const struct Element First ={ .inputPxselRegister = (uint8_t *)&P3SEL, .inputPxsel2Register = (uint8_t *)&P3SEL2, .inputPxoutRegister = (uint8_t *)&P3OUT, .inputPxdirRegister = (uint8_t *)&P3DIR, .inputBits = BIT3, .baseCnt = base_cnt, .threshold = threshold }; Please help to explain about the '.' at First element. Thank in advance! Quote Link to post Share on other sites
NurseBob 111 Posted July 12, 2016 Share Posted July 12, 2016 my google query: C struct tutorial About 2,610,000 results(0.29 seconds) A place to start... http://www.tutorialspoint.com/cprogramming/c_structures.htm Rei Vilo 1 Quote Link to post Share on other sites
MSPLife 2 Posted July 14, 2016 Author Share Posted July 14, 2016 Yep, I read that before, but the dot '.' at the beginning of the syntax make me confuse, which I have not seen at any tutorial. Quote Link to post Share on other sites
greeeg 460 Posted July 15, 2016 Share Posted July 15, 2016 See "2.4.2.3 Initializing Structure Members" Here https://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Declaring-Structure-Variables-After-Definition There are a few other ways to assign constant data in structures. It's not normally seen, I'm not sure why. I find it much easier to read/understand. MSPLife, Fmilburn and zeke 3 Quote Link to post Share on other sites
MSPLife 2 Posted July 17, 2016 Author Share Posted July 17, 2016 Thank you so much! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.