3

While reading about various IoT messaging protocols I came across a structure defined as below:

enum TempScale {
   CELSIUM,
   KELVIN,
   FARENHEIT
};

struct TempSensorType {
   short id;
   float temp;
   float hum;
   TempScale scale;
};
#pragma keylist TempSensorType id

My question is: What does this #pragma keylist keyword do and where can I find some documentation about using #pragma preprocessor directives (I believe it is such directive..).

Thanks.

lewiatan
  • 1,126
  • 2
  • 21
  • 37
  • Which particular compiler (version)? – πάντα ῥεῖ Jul 21 '15 at 19:40
  • Any use of `#pragma` is **strictly implementation defined**. Indeed that is the *purpose* of `#pragma`. So the **only** place any `#pragma` *could* be documented is the compiler manual. (That `#pragma` is strictly non-portable should be obvious.) – DevSolar Jul 22 '15 at 11:16
  • Thanks DevSolar. This made me look into clang and gcc documentation and search there for pragmas. – lewiatan Jul 22 '15 at 21:30

3 Answers3

4

The #pragma you are looking at is the PrismTech method for defining a key value within an OMG-DDS (Data Distribution Service for Real-Time Systems) Type structure. In this case, it is defining the short 'id' as a key value. The comparable RTI definition would be

struct TempSensorType {
    short id; //@key
    float temp;
    float hum;
    TempScale scale;
}

For interoperability between vendors' implementations, you can safely do

struct TempSensorType {
    short id; //@key
    float temp;
    float hum;
    TempScale scale;
}
#pragma keylist TempSensorType id

because the RTI compiler ignores the pragmas, and the PT compiler ignores the //@key.

This will change with future versions of the specification for Extensible Types, which will define a standard method for all vendors to support.

Note that if you were looking at a generic list of IoT messaging protocols, the concept of a "key" value may not exist in the other messaging protocols you were looking at.

rip...
  • 996
  • 5
  • 20
1

Note that for DDS implementations that comply with the recently-adopted OMG DDS-XTYPES specification (http://www.omg.org/spec/DDS-XTypes/) the standard portable way to specify keys is either:

struct SensorType {
    @key short id;
    float temp;
    float hum;
    TempScale scale;
}

Or alternatively (to avoid breaking IDL compilers that do not understand the IDL annotations):

struct SensorType {
    short id; //@key
    float temp;
    float hum;
    TempScale scale;
}
Gerardo Pardo
  • 1,001
  • 8
  • 5
0

Note that the explicit key-list specification via the pragma allows to define a ordering in the keys which - depending on the use-case - could have noticable performance impact on maintaining (filling/reading/querying/filtering) the 'multi-dimensional-storage' for a dataReader (and/or durability-service)