How to type cast elements of a huge array initialized with numbers
I have a third party C code which has large arrays of type float initialized with floating point numbers. Example:
float myArray[] = {1.2, 2.5, ....}; /*has thousands of elements*/
When I compile, I get the warning "truncation from double to float". I would like to get rid of this warning. If the array size was small (e.g. two), I could use standard type casting and manually update the code as follows:
float myArray[] = {1.2f, 2.5f};
or
float myArray[] = {(float) 1.2, (float) (2.5)};
However, due to the large number of elements, updating manually is not practical. Do I have to write a script that edits the source code and puts "f" after the numbers or is there an easier way for type casting the whole array with just one casting? Example:
float开发者_开发技巧 myArray[] = (float){1.2, 2.5, ...} /*does not work, issues syntax error*/
Find a text editor with search and replace, such as MS notepad, then have it replace every occurrence of the string "," with "f,".
精彩评论