Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » DSDP - Real-Time Software Components (RTSC) » typedefs in the RTSC spec world
typedefs in the RTSC spec world [message #2462] Tue, 05 May 2009 21:59
Amit Mookerjee is currently offline Amit MookerjeeFriend
Messages: 47
Registered: July 2009
Discussion on typedefs in RTSC

I will post this mail chain to the newsgroup.

Best Wishes

Amit Mookerjee

------------------------------------------------------------ --------------------

From: Bob Frankel []
Sent: Tuesday, May 05, 2009 12:47 PM
To: Mookerjee, Amit
Subject: Re: typedefs in the RTSC spec world

in retrospect, we should have had this conversation on the rtsc

Mookerjee, Amit wrote:


Great explanation!


Best Wishes

Amit Mookerjee

------------------------------------------------------------ --------------------

From: Bob Frankel []
Sent: Tuesday, May 05, 2009 7:51 AM
To: Mookerjee, Amit
Subject: Re: typedefs in the RTSC spec world

this "feature" of C -- that struct (and enum) tags are in their own
namespace -- has always been a source of confusion; C++ "fixed" the
problem by effectively having the construct 'struct S { ... }' mean
'typedef struct S { ... } S'. in the TISB coding standards, for instance,
we've always recommend including the struct (enum) tag when defining a
struct (enum) typedef.... in the case of a struct, you *must* included
the tag if you want to reference the struct type inside its own

typedef struct TreeNode TreeNode;
struct TreeNode {
TreeNode* left;
TreeNode* right;

now, you can do this "all at once", but then you'd have to reference the
struct type by its "tag" (which happens to be the same, since they are
really in different namespaces).

typedef struct TreeNode {
struct TreeNode* left;
struct TreeNode* right;
} TreeNode;

[the tisb coding conventions dictate the first pattern]

to keep the spec a little cleaner looking, we simply allow....

struct TreeNode {
TreeNode* left;
TreeNode* right;

[we automatically generate the extra 'typedef struct TreeNode TreeNode';
incidently, this is how you declare this type in C++; i also think C99 and
possibly GCC support this form now???]

as it turns out, 'struct S' *is* a new (and distinct!!!) type from any
other; a 'typedef' (contrary to the name) does *not* create a new type!!!!
the latter is effectively an alias for some *existing* type; the name of
the typedef, of course, will generally carry some semantics -- but it is
*not* enforced by the compiler. i can, for example, typedef 'Weight' and
'Distance' to 'Int' -- and yet i can free mix them in a program!!!!

both 'struct S' and 'enum E' truly create *new* types (though the latter
can be coerced into integers).... wrapping these declarations in a typedef
does *not* create a new type by rather an alias for an existing one....

Mookerjee, Amit wrote:


In some prototyping work I wrote a target module in the following manner:

module H264Enc {


typedef struct {

int x;

} MotionVector;



Int32 process(Int32 *input,Int32 *output);




generating interfaces for package codecs.h264enc (because
package/ is older than H264Enc.xdc) ...

translating H264Enc

"codecs/h264enc/H264Enc.xdc", line 9: no viable alternative at input

It appears that typedef of structures is not supported in the spec.

I could work around the problem by defining a struct

struct MotionVector


Int16 x;

Int16 y;


And then using it in a fairly convenient way


struct Instance_State {

MotionVector MV[352][288];


However, I should have been able to use typedef as well.

On the other hand typedefs like

typedef int foo;

work as expected.

This is non-intuitive for a C programmer. Is there any rationale for the
support of typedefs in this manner?

Best Wishes

Amit Mookerjee

Texas Instruments Inc.
Previous Topic:How to wait on proxy module startup?
Next Topic:pb running some commands in lesson 2 of packaging primer
Goto Forum:

Current Time: Mon Oct 02 21:07:42 GMT 2023

Powered by FUDForum. Page generated in 0.02040 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top