This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F28335: CCS6.0 abs()function problem

Part Number: TMS320F28335


Tool/software: TI C/C++ Compiler

Dears ,

    I am using TMS320F28335 and deug in CCSV6.0, have some question about the abs() function 

 1. If  I use the abs() to calculate a value which  out of the signed int  ,  for example < -32768 , the result is NG

2. If I use the labs() to do the same calc,  the result is OK

 

 So the proble is very clear , the abs() function only calc the signed int ,  If calc  lont int , must use the labs()

My question is 

    I dont  have any  technical document  about the abs(),or ,the labs(), where can I find that ?

    I know abs() is in  <stdlib.h>,but I do not  know anything about this lib.

   This problem shound be avoid before  it happened in our consumer‘s using , But unfortunately , it really happened ,So  I must make sure that never happened again

  Any fingers to the right  direction  would be  grateful

 thank  you!

   

  • Both abs and labs are standard C functions, defined in C standard ISO 9899. The C99 standard says (Section 7.20.6.1 "The abs, labs, and llabs functions") "If the result cannot be represented, the behavior is undefined." The absolute value of INT_MIN is not representable as an int, so you get undefined behavior, and thus garbage. It is the programmer's responsibility to consider whether the mathematical result might not fit in the type of the abs function, and to call the labs function instead.
  • Archaeologist ,Thanks very much