typedefs in the RTSC spec world [message #2462] |
Tue, 05 May 2009 21:59 |
Amit Mookerjee Messages: 47 Registered: July 2009 |
Member |
|
|
Discussion on typedefs in RTSC
----------------------------------------------------
I will post this mail chain to the newsgroup.
Best Wishes
Amit Mookerjee
------------------------------------------------------------ --------------------
From: Bob Frankel [mailto:bios.bob.frankel@gmail.com]
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
newsgroup....
Mookerjee, Amit wrote:
Bob,
Great explanation!
Thanks.
Best Wishes
Amit Mookerjee
------------------------------------------------------------ --------------------
From: Bob Frankel [mailto:bios.bob.frankel@gmail.com]
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
definition....
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:
Bob,
In some prototyping work I wrote a target module in the following manner:
module H264Enc {
typedef struct {
int x;
} MotionVector;
instance:
create();
Int32 process(Int32 *input,Int32 *output);
internal:
.
}
generating interfaces for package codecs.h264enc (because
package/package.xdc.inc is older than H264Enc.xdc) ...
translating H264Enc
"codecs/h264enc/H264Enc.xdc", line 9: no viable alternative at input
'struct'
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
internal:
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.
|
|
|
Powered by
FUDForum. Page generated in 0.02040 seconds