Duplicate typedef definitions

Let’s say that I have two independent packages, A and B, each of which contain the following line:

typedef bit [7:0] t_dyn_byteArray; // dynamic byte array

If I have 3rd package, C, which imports packages A and B.

The simulator is flagging an error on my very first declaration of type t_dyn_byteArray.
I would prefer not to create a “global” typedefs package which would be important by all 3 packages. Can I keep the original definitions in package A, and B, and still protect C from a typedef “collision”?


package A;
        typedef bit [7:0] t_dyn_byteArray[];
endpackage

package B;
        typedef bit [7:0] t_dyn_byteArray[];
endpackage

package C;
        import A::*;
        import B::*;

         A::t_dyn_byteArray foo;
endpackage

One other piece of unsolicited advise, be careful with your 2 t_dyn_byteArray typedefs, since they are declared independently they are considered 2 separate types, so having a single ‘global’ type may actually be your best bet

In reply to alexgran:

Two other things you can do are:

Similar to Alex’s suggestion, you can explicitly import one of the typedefs so there would be no wildcard conflict

package C;
        import A::*;
        import A::t_dyn_byteArray;
        import B::*;
 
        t_dyn_byteArray foo;
endpackage

However, I would strongly discourage using the same identifier in two different packages where you intend to import both packages in the same scope. A better solution would be to create a common package and then export the identifers from that common package so that they would be imported as package A or B


package common;
  typedef bit [7:0] t_dyn_byteArray[];
endpackage
package A;
  import common::*;
  export common::t_dyn_byteArray;
 // other A stuff      
endpackage
 
package B;
  import common::*;
  export common::t_dyn_byteArray;
 // other B stuff      
endpackage
 
package C;
        import A::*;
        import B::*;
 
         t_dyn_byteArray foo; // no identifier conflict
endpackage

In reply to dave_59:

I reworked my packages and now have a single typedef declaration; works great. Thanks for the good suggestions, Dave and Alex.

The exporting looks like an interesting technique, but I think with my personality it would bite me; I’d forget about the export and then not understand how package C was acquiring a “buried” typedef.