View previous topic :: View next topic |
Author |
Message |
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
Init struct with memset, work? |
Posted: Sun Jan 02, 2005 5:24 pm |
|
|
Hi,
Is possible and work initialize a struct con memset?
Code: |
struct _ST_
{
int a;
int b;
char x[ 10 ];
} ST;
...
...
memset( &ST, 0x00, sizeof( ST ) );
...
...
|
|
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Sun Jan 02, 2005 11:55 pm |
|
|
According to the manual, yes. The description for memset in the manual is the same as memcopy and memmove, CCS manual is full of mistakes like that. But what you want to do is in one of the examples:
Quote: |
MEMSET()
Syntax: memset (destination, value, n)
Parameters: destination is a pointer to memory, value is a 8 bit int,
and n is a 8 bit int.
Returns: undefined
Function: Copies n bytes from source to destination in RAM. Be
aware that array names are pointers where other variable
names and structure names are not (and therefore need a
& before them).
Memmove performs a safe copy (overlapping objects
doesn't cause a problem). Copying takes place as if the n
characters from the source are first copied into a
temporary array of n characters that doesn't overlap the
destination and source objects, and then the n characters
from the temporary array are copied to destination.
Built-In Functions
119
Availability: All devices
Requires Nothing
Examples:
memset(arrayA, 0, sizeof(arrayA));
memset(arrayB, '?', sizeof(arrayB));
memset(&structA, 0xFF, sizeof (structA));
Example Files: None
Also See: memcpy()
|
|
|
|
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Mon Jan 03, 2005 7:15 am |
|
|
I try to fill with 0x00 a struct with the memset, but not working. Work this for somebody?? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 03, 2005 12:54 pm |
|
|
Quote: | I try to fill with 0x00 a struct with the memset, but not working.
Work this for somebody? |
Post a complete test program (not just a code fragment), and give your
version of the compiler. |
|
|
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Wed Jan 05, 2005 11:35 am |
|
|
PCM
This is the code
Code: | 0000 07587 .................... memset( &MSG_RX, 0x00, sizeof( MSG_RX ) );
0442 0E10 07588 MOVLW 10
0444 6E01 07589 MOVWF 01
0446 6AEA 07590 CLRF FEA
0448 0EEF 07591 MOVLW EF
044A 6EE9 07592 MOVWF FE9
044C 6AEE 07593 CLRF FEE
044E 2E01 07594 DECFSZ 01,F
0450 D7FD 07595 BRA 044C
|
What you do think????? |
|
|
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Wed Jan 05, 2005 12:45 pm |
|
|
PCM,
The problem is that memset support int8 for the n bytes to set, and my struct hace 272 bytes.!!!!
Is possible change this in the memset???? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jan 05, 2005 1:01 pm |
|
|
Add a new 16-bit memset function.
Code: | //-----------------------------------------------------------------------------
// A version of memset that allows a 16-bit length i.s.o. the standard 8-bit length.
//-----------------------------------------------------------------------------
void memset16(int8 *Destination, int8 Value, int16 Len)
{
while (Len > 0)
{
*Destination++ = Value;
Len--;
}
} |
|
|
|
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Wed Jan 05, 2005 1:29 pm |
|
|
ckielstra,
Your routine not work for set my struct!, you test this with struct?
Thank you very much! |
|
|
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Wed Jan 05, 2005 1:35 pm |
|
|
ckielstra,
This is the answer from CCS
This message is a reply to CCS e-mail id: 5A1131
That is a limitation now however we will allow larger constants in the next release (3.216).
===========================================================================
CCS PIC C Compiler home: www.ccsinfo.com/picc
Software download page: www.ccsinfo.com/download.shtml
Latest Compiler news: www.ccsinfo.com/news.html
If you would like to be notified when the next compiler
version comes out go to www.ccsinfo.com/cgi-bin/email.cgi
=========================================================================== |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 05, 2005 1:35 pm |
|
|
If you will do these two things, then more testing can be done:
Quote: | Post a complete test program (not just a code fragment), and
give your version of the compiler. |
|
|
|
|