CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Fun PCD 5.123 bug with passing structures

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
allenhuffman



Joined: 17 Jun 2019
Posts: 665
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

Fun PCD 5.123 bug with passing structures
PostPosted: Wed May 13, 2026 7:32 am     Reply with quote

CCS support is aware of this, but I ran into an issue where 1 == 1 was not tru ;-) Here is the test program:

Code:
#include "main.h"

#include <stdint.h>

typedef struct
{
   uint8_t  type;
   uint8_t  length;
   uint16_t offset; // or uint8_t if not struct is > 255 bytes.
} tlv_offset_entry_t;


tlv_offset_entry_t testTLV[] =
{
    { 1, 10, 100 },
    { 2, 20, 200 },
    { 0, 0, 0 }
};


void test (tlv_offset_entry_t * table)
{
    unsigned int type = 1;  // This will fail
    //uint8_t type = 1;     // This will work
   
    printf ("test: Is %u == %u? ", table[0].type, type);
           
    if (table[0].type == type)
    {
        // Yes
        puts ("Yes\r\n");
    }
    else
    {
        // No
        puts ("No\r\n");
    }
}


void main()
{
    unsigned int type = 1;
   
    printf ("main: Is %u == %u? ", testTLV[0].type, type);
           
    if (testTLV[0].type == type)
    {
        // Yes
        puts ("Yes\r\n");
    }
    else
    {
        // No
        puts ("No\r\n");
    }

    test (testTLV);
}


This will run and the compare in main() works fine, but the compare against the same value once passed to a function will fail. The output:

Code:
main: Is 1 == 1? Yes

test: Is 1 == 1? No


So even though it prints the proper value, the compare fails. From what support said, they think the optimizer may have removed something that would have cleared half of the 16-bit value used in the compare when comparing against the uint8_t value.

Fun one. This took me down quite the rabbit hole to figure out where the issue was.

My workaround of just using an uint8_t worked for THIS example and my original version, but once I shifted some code around and changed the size or whatever, it stopped working again. I am testing a second workaround today, but support may beat me to it.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202, 24FJ64GA002 and 24FJ1024GA606.
Ttelmah



Joined: 11 Mar 2010
Posts: 20078

View user's profile Send private message

PostPosted: Wed May 13, 2026 12:02 pm     Reply with quote

That suspiciously sounds like they may have re-introduced a problem they
had about 50 versions ago.
They were getting the sizes wrong in PCD when pointers were passed,
not performing the arithmetic correctly. You should be able to see if that
is happening with an ICD.
Does it work correctly on say 5.121?.
If so, learn the lesson that many of the posters here will quote.
Don't change versions unless you need a feature from the newer version.
It saves a lot of problems.
allenhuffman



Joined: 17 Jun 2019
Posts: 665
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Wed May 13, 2026 12:07 pm     Reply with quote

Ttelmah wrote:
That suspiciously sounds like they may have re-introduced a problem they
had about 50 versions ago.
They were getting the sizes wrong in PCD when pointers were passed,
not performing the arithmetic correctly. You should be able to see if that
is happening with an ICD.
Does it work correctly on say 5.121?.
If so, learn the lesson that many of the posters here will quote.
Don't change versions unless you need a feature from the newer version.
It saves a lot of problems.


Very true.

Though every company I have ever contacted to get help with an older version always says "try it on the current supported version then get back to us" ;-)
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202, 24FJ64GA002 and 24FJ1024GA606.
Ttelmah



Joined: 11 Mar 2010
Posts: 20078

View user's profile Send private message

PostPosted: Thu May 14, 2026 11:36 am     Reply with quote

When I have had problems with a new release, one of the first things CCS
often asks if if the fault was there with the previous release(s), and if it
only appeared at a particular version, they will suggest you carry on with
the older code until they have a fix.
Having the past 'history' allows them to speed up identifying what they
have got wrong.
I've had Microsoft do the same when a new driver update causes issues.
allenhuffman



Joined: 17 Jun 2019
Posts: 665
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu May 14, 2026 11:36 am     Reply with quote

Ttelmah wrote:
When I have had problems with a new release, one of the first things CCS
often asks if if the fault was there with the previous release(s), and if it
only appeared at a particular version, they will suggest you carry on with
the older code until they have a fix.
Having the past 'history' allows them to speed up identifying what they
have got wrong.


Well, we are running 5.123 because it fixes an issue we found with the previous release ;-)
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202, 24FJ64GA002 and 24FJ1024GA606.
allenhuffman



Joined: 17 Jun 2019
Posts: 665
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu May 14, 2026 11:46 am     Reply with quote

For anyone else playing along at home...

Looks like we encountered our previous issue in 5.118. They provided an internal 5.122 with a fix, and then it was rolled in to the release of 5.123.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202, 24FJ64GA002 and 24FJ1024GA606.
Ttelmah



Joined: 11 Mar 2010
Posts: 20078

View user's profile Send private message

PostPosted: Sat May 16, 2026 10:58 am     Reply with quote

As a silly question, would it be possible for you to pass by reference?,
I find I was having an issue with passing pointers. The compiler did not
correctly know about the size of structures when they were handled using
pointers, but they did work if I passed by reference instead.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group