No Name Collisions


When we generate C code, all names are globals – there are no namespaces in C!
So, when a file (or package etc) defines a component (or protocol, ect), that happens to have the same name as one in another file, they clash. This is known as a Name Collision.

This has to be prevented!


There are several ways how to circumvent that, like:

  1. Use ‘static’ when possible – this make the issue smaller, but does not solve it (IMHO)

  2. Use a C++ compiler, that has namespaces – it’s a workaround – I don’t prefer that

  3. Prefix all generated names with a NS-prefix (NS::NameSpace)

    For example component Sieve should result not in:

    • struct CC_B_ComponentInterface cc_CI_Sieve,

    • struct CC_B_ComponentClass cc_C_Sieve, and

    • typedef struct { … } CC_C_Sieve.

    But in:

    • struct CC_B_ComponentInterface {NS_hashId}_cc_CI_Sieve,

    • struct CC_B_ComponentClass {NS_hashId}_cc_C_Sieve, and

    • typedef struct { … } {NS_hashId}_CC_C_Sieve.

      Where {NS_hashId}, the result of NS_hashId(dottedNamePath:str)->shortSting is stable

      • python’ hash() will not work

      • See HashIds for an examle – but not accepting string-input

      • MD5 is provably fine – no need to be (crypto) safe

    Or, possible the order should be

    • struct CC_B_ComponentInterface cc_CI_{NS_hashId}_Sieve,

    • struct CC_B_ComponentClass cc_C_{NS_hashId}_Sieve, and

    • typedef struct { … } CC_C_{NS_hashId}_Sieve.

Pre/In/PostFixes in generated CC2Py code

The CC2Cpy compiler generated C-code, using a lot of pre-, in- and postfixed.

They are documented later ..


comments powered by Disqus