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

structures

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



Joined: 13 Aug 2004
Posts: 59
Location: Turkey

View user's profile Send private message Visit poster's website

structures
PostPosted: Fri Dec 20, 2024 7:01 am     Reply with quote

hi I've tried this kind of structure on ccs pic 4.114 when compiling
get expression must evaluate to a constant , expecting declaration, expecting a (, . is it possible to construct this kind of struct in ccs.


typedef struct {
int1 up1;
int1 down1;
int1 up2;
int1 down2;
int1 left1;
int1 right1;
int1 LR_2;
int1 north1;
int1 south1;
int1 NS_2;
} IOpin_t;

IOpin_t IOpins = {
.up1 = up1,
.down1 = down1,
.up2 = up2,
.down2 = down2,
.left1 = left1,
.right1 = right1,
.LR_2 = LR_2,
.north1 = north1,
.south1 = south1,
.NS_2 = NS_2
};



cheers
_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Fri Dec 20, 2024 7:46 am     Reply with quote

No.
Use of the structure member operator like this is not originally C!.....
It is part of C++, that many C's now allow. GCC for example. It is now part
of the newer ANSI standard, but later than CCS supports.
You can write to the individual members at declaration just by putting the
values separated by commas, but values have to be constants in your version.
4.114, is very old. Some more sophisticated initialisations are supported in
more recent versions, but not this.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 20, 2024 9:55 am     Reply with quote

just a comment...

It may be 'better' to have 'unused filler' bits to make structure to be 8 bits or 16 bits

Usually you can arrange bits into logical groups.

At one time there was a problem, accessing bit across byte 'boundaries'.
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Dec 20, 2024 7:38 pm     Reply with quote

Does int1 turn in to something other than a byte? I thought I just saw it in one of the header files and it was a bool?
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Fri Dec 20, 2024 11:27 pm     Reply with quote

allenhuffman wrote:
Does int1 turn in to something other than a byte? I thought I just saw it in one of the header files and it was a bool?


It can yes. The PIC supports general bit set/test/clear/etc instructions, so the compiler will often try to optimize int1 variables using those. Sometimes it will promote to a byte, but it depends on the situation.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sat Dec 21, 2024 1:05 am     Reply with quote

int1, is a bit in a byte.
As Jay says, the compiler will optimise to use bit instructions where these
exist, and combines multiple ones to form a byte.
Where there is an issue, is when using bit fields in a structure, and these
fields cross a byte boundary (on PIC12/14/16/18), or a word boundary
(on PIC 24/30/33). This can cause issues. So (for example):
Code:

struct {
   int bits :4;
   int more bits:5;
} variable;

or when using int1's and mixing with other values:
structure {
int1 bit;
int value;
} variable;
[/code]

If is better in both cases to try to ensure that you declare the big values
first and avoid declarations that cross the chip's basic type sizes.

The first, the compiler will warn about, and the second on later compilers
is fine, with the compiler just leaving 7 bits of space. However just better
not to actually rely on this behaviour, especially with a compiler as old as
yours.
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