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

Init struct with memset, work?

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



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

Init struct with memset, work?
PostPosted: Sun Jan 02, 2005 5:24 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 02, 2005 11:55 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 03, 2005 7:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 03, 2005 12:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 05, 2005 11:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 05, 2005 12:45 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 05, 2005 1:01 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 05, 2005 1:29 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 05, 2005 1:35 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 05, 2005 1:35 pm     Reply with quote

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.
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