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

Code of sprintf()

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



Joined: 15 Jan 2010
Posts: 8

View user's profile Send private message Send e-mail

Code of sprintf()
PostPosted: Mon Dec 13, 2010 7:03 am     Reply with quote

Where I can find the code of sprintf() implementation in CCS environment ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 9:25 am     Reply with quote

You can't.
It is worth understanding that the function is 'segmented'. Only parts of the whole code loads, depending on what options are used, so there is no single code for the functions. CCS, don't publish sources for their internal functions.
There have been some alternative printf functions posted in the past and some in the code library, which could be adapted to output to a string.
If you rem out the 'nolist' option in the include file for your processor, the assembler becomes available.

Best Wishes
RUFINOGG



Joined: 15 Jan 2010
Posts: 8

View user's profile Send private message Send e-mail

sprintf()
PostPosted: Mon Dec 13, 2010 7:23 pm     Reply with quote

Ttelmah wrote:
You can't.
It is worth understanding that the function is 'segmented'. Only parts of the whole code loads, depending on what options are used, so there is no single code for the functions. CCS, don't publish sources for their internal functions.
There have been some alternative printf functions posted in the past and some in the code library, which could be adapted to output to a string.
If you rem out the 'nolist' option in the include file for your processor, the assembler becomes available.

Best Wishes

Thanks for the reply, but I need to pass all arguments to a hexadecimal array, not a string, so I need to modify code:
Code:

unsigned int32 intxx;
intxx = 0x12345678;

sprintf (array, "% lX intxx ........%s" .......stringXX.... etc.
 

Result:
array [0] = 0x12 NOT in ASCII 0x31, array[1] = 0x32, array[1] = 0x33 ..... .... NOT ASCII

array [1] = 0x34
array [2] = 0x56
array [3] = 0x78
etc ......
......
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 7:57 pm     Reply with quote

I think you just want to extract bytes from an int32 variable.
Look at the make8() function in the CCS manual. It will do it for you.
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Tue Dec 14, 2010 5:15 am     Reply with quote

And (of course), the old chestnut of unions rears it's head here again:
Code:

union {
   int32 val;
   int8 b[4];
} splitter;

splitter.val=0x12345678;

//now splitter.b[0] to b[4] are the array you want _except_ for the byte order....


No moving/copying etc necessary. All you are doing is declaring two variable 'types' to occupy the same memory space. An array of four bytes, and the int32 value.
Saves having to relocate the bytes into the array (with make8), but unfortunately, you want the bytes in the reverse order they are stored in memory.

Best Wishes
RUFINOGG



Joined: 15 Jan 2010
Posts: 8

View user's profile Send private message Send e-mail

sprintf()
PostPosted: Tue Dec 14, 2010 5:33 am     Reply with quote

Ttelmah wrote:
And (of course), the old chestnut of unions rears it's head here again:
Code:

union {
   int32 val;
   int8 b[4];
} splitter;

splitter.val=0x12345678;

//now splitter.b[0] to b[4] are the array you want _except_ for the byte order....


No moving/copying etc necessary. All you are doing is declaring two variable 'types' to occupy the same memory space. An array of four bytes, and the int32 value.
Saves having to relocate the bytes into the array (with make8), but unfortunately, you want the bytes in the reverse order they are stored in memory.

Best Wishes

Thanks. If I can not change sprintf () this can be a solution to compose a hexadecimal array (string and variables)
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