UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
286 Views
Registered: ‎06-27-2018

How to treat char type as signed char

Hi,

In our system we need to include an external library like a Eigen, g2o, to process numerical processing. These libraries treated the char type as signed char, because of most software compiler treated so.

But SDSoC treate as unsigned char. And these libraries are used the huge number of char variable.

Is there a way to treat char type as signed char in SDSoC?

Thanks.

0 Kudos
3 Replies
Teacher xilinxacct
Teacher
202 Views
Registered: ‎10-23-2018

Re: How to treat char type as signed char

@kousei.iwabuchi 

I am unaware that char=unsigned char in SDSoc... I would be interested in hearing where you got that info...

The 2 data types can indeed hold the same values, and for many operations other then math they will do the same thing. And depending on how you 'display' the value you might see something unexpected.

Of course, printing, casting and assignments to wider values would need to be consistently handled.

I would fully expect a compliant compiler to default to being a difference. (e.g. gcc you can force a difference using -funsigned-char )so, 'maybe' some library was compiled in that fashion.

Again, if you have a documented source that says SDSoc always treats char as unsigned char, I would be interested in learning something new.

Hope that Helps

If so, Please mark as solution accepted. Kudos also welcomed. :-)

0 Kudos
192 Views
Registered: ‎06-27-2018

Re: How to treat char type as signed char

I have never seen about this in document, but I noticed the code.

When this code is compiled by gcc, output "minus", SDSoC is "minus".

char c = -1;
if ( c < 0 ) {
    printf("minus\n");
} else {
    printf("plus\n");
}

This is math processing, so I should have specified the sign.

According to the C ++ specification, whether char is signed or unsigned is implementation-dependent, so SDSOc is C ++ compliant.

Thanks.

0 Kudos
Teacher xilinxacct
Teacher
185 Views
Registered: ‎10-23-2018

Re: How to treat char type as signed char

@kousei.iwabuchi 

Thanks for your kind follow-up... And your example perfectly illustrates my conclusion... char 'is' indeed equivalent to 'signed char' by default.

As your topic was 'How to treat char type as signed char'... made me think you thought otherwise... so, it sounds like you have proved to yourself that is does treat it the same...

Again, thanks for following up, and removing the doubt. :-) I like it when things work as expected. :-)

0 Kudos