| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			scanan
 
 
  Joined: 13 Aug 2004 Posts: 82 Location: Turkey 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				| structures | 
			 
			
				 Posted: Fri Dec 20, 2024 7:01 am     | 
				     | 
			 
			
				
  | 
			 
			
				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: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Dec 20, 2024 7:46 am     | 
				     | 
			 
			
				
  | 
			 
			
				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: 9589 Location: Greensville,Ontario 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Dec 20, 2024 9:55 am     | 
				     | 
			 
			
				
  | 
			 
			
				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: 643 Location: Des Moines, Iowa, USA 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Dec 20, 2024 7:38 pm     | 
				     | 
			 
			
				
  | 
			 
			
				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: 1401
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Dec 20, 2024 11:27 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | 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: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sat Dec 21, 2024 1:05 am     | 
				     | 
			 
			
				
  | 
			 
			
				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. | 
			 
		  | 
	
	
		  | 
	
	
		
			scanan
 
 
  Joined: 13 Aug 2004 Posts: 82 Location: Turkey 
			
			 
			 
			
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Dec 25, 2024 5:24 am     | 
				     | 
			 
			
				
  | 
			 
			
				many thanks for your precious comments _________________ Dr Suleyman CANAN
 
R&D Electronic Engineer
 
https://suleymancanan.wordpress.com
 
 
Do whatever you do with amateur spirit - 
 
But always feel professional. | 
			 
		  | 
	
	
		  | 
	
	
		 |