Solved

Assert unique values for a struct member during compile.

Posted on 2014-03-01
6
223 Views
Last Modified: 2014-03-03
I have an embedded application where I need to guarantee that a structure member has a unique value in a table of those structures. I need to ensure that the startingPosition is always unique.

const dataLogDefinition dataLogDefinitions PPAGE_E5 = {
		version:  PROTOCOL_VERSION,
		sizeOfEntry:  sizeof(dataLogField),
		entries: {
				 {.startingPosition = offsetof(CoreVar, IAT), .size = bitSize(CoreVar, IAT), .name = "IAT", .description = "Variable 1", 0,0},
				 {.startingPosition = offsetof(CoreVar, CHT), .size = bitSize(CoreVar, CHT), .name = "CHT", .description = "Variable 2", 0,0},
		}
};

Open in new window


Any ideas would be appreciated.
0
Comment
Question by:sean-keys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 39897547
Hi Sean,

Is the table static?  How many items are in the table?  Is uniqueness enough or do they also need to be sequential, non-descending, random, etc.
0
 

Author Comment

by:sean-keys
ID: 39897563
Hi,

Yes the table is static. The length will be variable but within reason 20-30 entries. They do not need to be sequential, I just need to make sure something does not end up in there twice.
0
 

Author Comment

by:sean-keys
ID: 39897577
https://git.libreems.org/libreems-suite/libreems-firmware/blob/dataLogDefProtocol/src/main/dataLogDefinitions.c

needs to describe the data here:

https://git.libreems.org/libreems-suite/libreems-firmware/blob/dataLogDefProtocol/src/main/inc/containerTypes.h#L72


The definitions need to remain seperate because they reside in flash while the other resides in RAM, which I have much less of.

Thanks!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 39897697
Easy enough.  :)

Note the two sample lines:

                         {.startingPosition = offsetof(CoreVar, IAT), .size = bitSize(CoreVar, IAT), .name = "IAT", .description = "Variable 1", 0,0},
                         {.startingPosition = offsetof(CoreVar, CHT), .size = bitSize(CoreVar, CHT), .name = "CHT", .description = "Variable 2", 0,0},

The first line contains the string "IAT" and the constant IAT.  IAT is defined in the header file.
The second line has the same characteristics, except that the values are "CHT" and CHT.

I suggest that you simply enumerate the items that you need.


enum
{
  SP_NULL=0,      // zero
  SP_IAT,
  SP_CHT,
  SP_TPS,
  SP_EGO,
  SP_MAP,
  SP_AAP,
  SP_BRV,
  SP_MAT,
  SP_MAX
};
0
 

Author Closing Comment

by:sean-keys
ID: 39900630
I guess the "right" way to do this would be to have a script generate both C source files. It seems enum, is as good as it gets :)
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 39900646
Well, for the specific application that you've shown, I don't think that a random/unique value is sufficient.  I believe that the value is also an index into the array of values returned from the PIC controller.  

You'll want to initialize the value to the correct index value.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ACL in Solaris 10 & AIX V6.1 to circumvent application required  grp:rwx 9 123
Line meaning 9 94
php56-php-mcrypt for rhel7 php56 1 158
Fill Null values 5 50
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question