Thread: don't know how to solve pointer to union of two different types??

  1. #1
    Registered User
    Join Date
    Mar 2020

    don't know how to solve pointer to union of two different types??

    I have the following simplified code and I need to have a formula take a uint16_t. This value however comes from multiple sources (ie multiple types) depending on who is calling the formula. The two issues I currently see in the debugger...
    1. pTx assignment how do I do this ?
    2. after I run the program the prtnVals don't look anything like the assignments??

    Can someone please help.

    /** * main.c
    #include <msp430.h>
    #include <stdint.h>
    #pragma LOCATION (pwmDiv, 0x1800);
    #pragma PERSISTENT(pwmDiv);
    volatile uint16_t pwmDiv = 50;
    uint16_t itoa(uint16_t k);
    union rtnVals
        volatile uint16_t Memory;
        float avg;
    union rtnVals *prtnVals;
    uint16_t test, lowByte = 2;
    uint16_t *pTx = **prtnVals;
    int main(void)
        WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
        prtnVals->avg = 4454.0;
        prtnVals->Memory = pwmDiv;
        test = itoa((((*pTx)) >> (4 * lowByte)) & 0x0F);
    uint16_t itoa(uint16_t k)
        if (k <= 9)
            return '0' + k;
            return 'A' + (k - 10);
    Last edited by ridgerunnersjw; 07-07-2022 at 05:44 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Your code makes no sense, and your image is broken.

    > prtnVals->avg = 4454.0;
    > prtnVals->Memory = pwmDiv;

    Given your union, all you have is
    prtnVals->Memory = pwmDiv;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer to union inside struct
    By lv2eof in forum C Programming
    Replies: 4
    Last Post: 05-28-2010, 06:55 PM
  2. Replies: 4
    Last Post: 01-06-2009, 02:08 AM
  3. Replies: 5
    Last Post: 08-05-2008, 10:24 AM
  4. How to convert integral types into pointer types?
    By rohit99 in forum C++ Programming
    Replies: 3
    Last Post: 03-20-2008, 09:57 AM
  5. pointer to pointer how do i solve following problem?
    By kobra_swe in forum C Programming
    Replies: 5
    Last Post: 07-19-2006, 04:49 PM

Tags for this Thread