structure extern with different type












0















I found the below warning in map file , the struct extern declaration TYPE got changed in file2.c declaration. Below warning from IAR compiler,
Please let me know what is the impact of below type cast.
what is the memory size in file2.c while link time ?



I am trying to find impacts of this implementation not the solution



"struct_tag" to "uint8"



Warning[w6]: Type conflict for external/entry "Block_01", in module file2.c against external/entry in module file1.c; different basic types  
/* In module file2.c: */
uint8 NvM_Block_01;
typedef unsigned char uint8;
/* In module file1.c: */
Block_01_T Block_01;
typedef struct Block_01_Tag Block_01_T;




typedef struct Block_01_Tag

{/* 4 bytes with CRC16 */

uint16 Data_01;
uint16 Crc_01;
}Block_01_T;


File1.c



Block_01_T Block_01 = {1234,1};


File2.c



extern unsigned char Block_01;
#define RPM_BLOCK (&Block_01)


Thanks
Damodaran










share|improve this question

























  • There's no type cast. You have the same variable declared with completely different types. It's a single char in File2.c, but a structure in File1.c. How do you expect that to work?

    – Barmar
    Nov 13 '18 at 1:29











  • "I am debugging the legacy code and i found this strange code." this is working and gets the address of first byte of struct, However in runtime i am not sure what linker links 4 bytes or 1 byte in File2.c

    – Damodaran
    Nov 13 '18 at 14:52











  • Where are you quoting that from? It's not in the question.

    – Barmar
    Nov 13 '18 at 15:39
















0















I found the below warning in map file , the struct extern declaration TYPE got changed in file2.c declaration. Below warning from IAR compiler,
Please let me know what is the impact of below type cast.
what is the memory size in file2.c while link time ?



I am trying to find impacts of this implementation not the solution



"struct_tag" to "uint8"



Warning[w6]: Type conflict for external/entry "Block_01", in module file2.c against external/entry in module file1.c; different basic types  
/* In module file2.c: */
uint8 NvM_Block_01;
typedef unsigned char uint8;
/* In module file1.c: */
Block_01_T Block_01;
typedef struct Block_01_Tag Block_01_T;




typedef struct Block_01_Tag

{/* 4 bytes with CRC16 */

uint16 Data_01;
uint16 Crc_01;
}Block_01_T;


File1.c



Block_01_T Block_01 = {1234,1};


File2.c



extern unsigned char Block_01;
#define RPM_BLOCK (&Block_01)


Thanks
Damodaran










share|improve this question

























  • There's no type cast. You have the same variable declared with completely different types. It's a single char in File2.c, but a structure in File1.c. How do you expect that to work?

    – Barmar
    Nov 13 '18 at 1:29











  • "I am debugging the legacy code and i found this strange code." this is working and gets the address of first byte of struct, However in runtime i am not sure what linker links 4 bytes or 1 byte in File2.c

    – Damodaran
    Nov 13 '18 at 14:52











  • Where are you quoting that from? It's not in the question.

    – Barmar
    Nov 13 '18 at 15:39














0












0








0








I found the below warning in map file , the struct extern declaration TYPE got changed in file2.c declaration. Below warning from IAR compiler,
Please let me know what is the impact of below type cast.
what is the memory size in file2.c while link time ?



I am trying to find impacts of this implementation not the solution



"struct_tag" to "uint8"



Warning[w6]: Type conflict for external/entry "Block_01", in module file2.c against external/entry in module file1.c; different basic types  
/* In module file2.c: */
uint8 NvM_Block_01;
typedef unsigned char uint8;
/* In module file1.c: */
Block_01_T Block_01;
typedef struct Block_01_Tag Block_01_T;




typedef struct Block_01_Tag

{/* 4 bytes with CRC16 */

uint16 Data_01;
uint16 Crc_01;
}Block_01_T;


File1.c



Block_01_T Block_01 = {1234,1};


File2.c



extern unsigned char Block_01;
#define RPM_BLOCK (&Block_01)


Thanks
Damodaran










share|improve this question
















I found the below warning in map file , the struct extern declaration TYPE got changed in file2.c declaration. Below warning from IAR compiler,
Please let me know what is the impact of below type cast.
what is the memory size in file2.c while link time ?



I am trying to find impacts of this implementation not the solution



"struct_tag" to "uint8"



Warning[w6]: Type conflict for external/entry "Block_01", in module file2.c against external/entry in module file1.c; different basic types  
/* In module file2.c: */
uint8 NvM_Block_01;
typedef unsigned char uint8;
/* In module file1.c: */
Block_01_T Block_01;
typedef struct Block_01_Tag Block_01_T;




typedef struct Block_01_Tag

{/* 4 bytes with CRC16 */

uint16 Data_01;
uint16 Crc_01;
}Block_01_T;


File1.c



Block_01_T Block_01 = {1234,1};


File2.c



extern unsigned char Block_01;
#define RPM_BLOCK (&Block_01)


Thanks
Damodaran







c struct linker compiler-warnings






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 1:20







Damodaran

















asked Nov 13 '18 at 0:55









DamodaranDamodaran

124




124













  • There's no type cast. You have the same variable declared with completely different types. It's a single char in File2.c, but a structure in File1.c. How do you expect that to work?

    – Barmar
    Nov 13 '18 at 1:29











  • "I am debugging the legacy code and i found this strange code." this is working and gets the address of first byte of struct, However in runtime i am not sure what linker links 4 bytes or 1 byte in File2.c

    – Damodaran
    Nov 13 '18 at 14:52











  • Where are you quoting that from? It's not in the question.

    – Barmar
    Nov 13 '18 at 15:39



















  • There's no type cast. You have the same variable declared with completely different types. It's a single char in File2.c, but a structure in File1.c. How do you expect that to work?

    – Barmar
    Nov 13 '18 at 1:29











  • "I am debugging the legacy code and i found this strange code." this is working and gets the address of first byte of struct, However in runtime i am not sure what linker links 4 bytes or 1 byte in File2.c

    – Damodaran
    Nov 13 '18 at 14:52











  • Where are you quoting that from? It's not in the question.

    – Barmar
    Nov 13 '18 at 15:39

















There's no type cast. You have the same variable declared with completely different types. It's a single char in File2.c, but a structure in File1.c. How do you expect that to work?

– Barmar
Nov 13 '18 at 1:29





There's no type cast. You have the same variable declared with completely different types. It's a single char in File2.c, but a structure in File1.c. How do you expect that to work?

– Barmar
Nov 13 '18 at 1:29













"I am debugging the legacy code and i found this strange code." this is working and gets the address of first byte of struct, However in runtime i am not sure what linker links 4 bytes or 1 byte in File2.c

– Damodaran
Nov 13 '18 at 14:52





"I am debugging the legacy code and i found this strange code." this is working and gets the address of first byte of struct, However in runtime i am not sure what linker links 4 bytes or 1 byte in File2.c

– Damodaran
Nov 13 '18 at 14:52













Where are you quoting that from? It's not in the question.

– Barmar
Nov 13 '18 at 15:39





Where are you quoting that from? It's not in the question.

– Barmar
Nov 13 '18 at 15:39












3 Answers
3






active

oldest

votes


















0














In file2.c, Block_01 is given type unsigned char, which is 1 byte in size. This will access the first byte of the structure Block_01_t, which will be part of Block_01_T.Data_01.






share|improve this answer
























  • *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes ?, in file2.c what is the size linker links or size is nothing to do while executing in file2.c ?, "I am debugging the legacy code and i found this strange code."

    – Damodaran
    Nov 13 '18 at 14:50











  • @Damodaran Yes, *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes, that is correct

    – Rob Newton
    Nov 13 '18 at 23:17



















0














You have two variables of the same name. Block_01 and different types. This is not allowed. You need to change one of them.



Block_01_T Block_01 = {1234,1};   // in File1.c
extern unsigned char Block_01; // in File2.c


If you want both files to refer to the same variable, you can use.



extern Block_01_T Block_01;  // in File2.c





share|improve this answer
























  • "I am debugging the legacy code and i found this strange code." Its working code, however i am not sure what are the impacts of this code

    – Damodaran
    Nov 13 '18 at 14:54



















0














The linker generally doesn't care about the size of object, just their addresses. The compiler reserves space in the object file that defines the object. In this case, the definition is in File1.c, which declares a structure containing two uint16, so it will most reserve at least 4 bytes.



According to the C standard, the consequences are undefined when you use Block_01 in File2.. But I think it's likely that it will be equivalent to giving it the same structure type declaration, and then using *(char *)(&Block_01).






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272237%2fstructure-extern-with-different-type%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    In file2.c, Block_01 is given type unsigned char, which is 1 byte in size. This will access the first byte of the structure Block_01_t, which will be part of Block_01_T.Data_01.






    share|improve this answer
























    • *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes ?, in file2.c what is the size linker links or size is nothing to do while executing in file2.c ?, "I am debugging the legacy code and i found this strange code."

      – Damodaran
      Nov 13 '18 at 14:50











    • @Damodaran Yes, *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes, that is correct

      – Rob Newton
      Nov 13 '18 at 23:17
















    0














    In file2.c, Block_01 is given type unsigned char, which is 1 byte in size. This will access the first byte of the structure Block_01_t, which will be part of Block_01_T.Data_01.






    share|improve this answer
























    • *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes ?, in file2.c what is the size linker links or size is nothing to do while executing in file2.c ?, "I am debugging the legacy code and i found this strange code."

      – Damodaran
      Nov 13 '18 at 14:50











    • @Damodaran Yes, *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes, that is correct

      – Rob Newton
      Nov 13 '18 at 23:17














    0












    0








    0







    In file2.c, Block_01 is given type unsigned char, which is 1 byte in size. This will access the first byte of the structure Block_01_t, which will be part of Block_01_T.Data_01.






    share|improve this answer













    In file2.c, Block_01 is given type unsigned char, which is 1 byte in size. This will access the first byte of the structure Block_01_t, which will be part of Block_01_T.Data_01.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 1:31









    Rob NewtonRob Newton

    37228




    37228













    • *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes ?, in file2.c what is the size linker links or size is nothing to do while executing in file2.c ?, "I am debugging the legacy code and i found this strange code."

      – Damodaran
      Nov 13 '18 at 14:50











    • @Damodaran Yes, *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes, that is correct

      – Rob Newton
      Nov 13 '18 at 23:17



















    • *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes ?, in file2.c what is the size linker links or size is nothing to do while executing in file2.c ?, "I am debugging the legacy code and i found this strange code."

      – Damodaran
      Nov 13 '18 at 14:50











    • @Damodaran Yes, *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes, that is correct

      – Rob Newton
      Nov 13 '18 at 23:17

















    *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes ?, in file2.c what is the size linker links or size is nothing to do while executing in file2.c ?, "I am debugging the legacy code and i found this strange code."

    – Damodaran
    Nov 13 '18 at 14:50





    *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes ?, in file2.c what is the size linker links or size is nothing to do while executing in file2.c ?, "I am debugging the legacy code and i found this strange code."

    – Damodaran
    Nov 13 '18 at 14:50













    @Damodaran Yes, *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes, that is correct

    – Rob Newton
    Nov 13 '18 at 23:17





    @Damodaran Yes, *(RPM_BLOCK + i) ; i 0 to 3 will access all the 4 bytes, that is correct

    – Rob Newton
    Nov 13 '18 at 23:17













    0














    You have two variables of the same name. Block_01 and different types. This is not allowed. You need to change one of them.



    Block_01_T Block_01 = {1234,1};   // in File1.c
    extern unsigned char Block_01; // in File2.c


    If you want both files to refer to the same variable, you can use.



    extern Block_01_T Block_01;  // in File2.c





    share|improve this answer
























    • "I am debugging the legacy code and i found this strange code." Its working code, however i am not sure what are the impacts of this code

      – Damodaran
      Nov 13 '18 at 14:54
















    0














    You have two variables of the same name. Block_01 and different types. This is not allowed. You need to change one of them.



    Block_01_T Block_01 = {1234,1};   // in File1.c
    extern unsigned char Block_01; // in File2.c


    If you want both files to refer to the same variable, you can use.



    extern Block_01_T Block_01;  // in File2.c





    share|improve this answer
























    • "I am debugging the legacy code and i found this strange code." Its working code, however i am not sure what are the impacts of this code

      – Damodaran
      Nov 13 '18 at 14:54














    0












    0








    0







    You have two variables of the same name. Block_01 and different types. This is not allowed. You need to change one of them.



    Block_01_T Block_01 = {1234,1};   // in File1.c
    extern unsigned char Block_01; // in File2.c


    If you want both files to refer to the same variable, you can use.



    extern Block_01_T Block_01;  // in File2.c





    share|improve this answer













    You have two variables of the same name. Block_01 and different types. This is not allowed. You need to change one of them.



    Block_01_T Block_01 = {1234,1};   // in File1.c
    extern unsigned char Block_01; // in File2.c


    If you want both files to refer to the same variable, you can use.



    extern Block_01_T Block_01;  // in File2.c






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 4:47









    Rishikesh RajeRishikesh Raje

    5,4591826




    5,4591826













    • "I am debugging the legacy code and i found this strange code." Its working code, however i am not sure what are the impacts of this code

      – Damodaran
      Nov 13 '18 at 14:54



















    • "I am debugging the legacy code and i found this strange code." Its working code, however i am not sure what are the impacts of this code

      – Damodaran
      Nov 13 '18 at 14:54

















    "I am debugging the legacy code and i found this strange code." Its working code, however i am not sure what are the impacts of this code

    – Damodaran
    Nov 13 '18 at 14:54





    "I am debugging the legacy code and i found this strange code." Its working code, however i am not sure what are the impacts of this code

    – Damodaran
    Nov 13 '18 at 14:54











    0














    The linker generally doesn't care about the size of object, just their addresses. The compiler reserves space in the object file that defines the object. In this case, the definition is in File1.c, which declares a structure containing two uint16, so it will most reserve at least 4 bytes.



    According to the C standard, the consequences are undefined when you use Block_01 in File2.. But I think it's likely that it will be equivalent to giving it the same structure type declaration, and then using *(char *)(&Block_01).






    share|improve this answer




























      0














      The linker generally doesn't care about the size of object, just their addresses. The compiler reserves space in the object file that defines the object. In this case, the definition is in File1.c, which declares a structure containing two uint16, so it will most reserve at least 4 bytes.



      According to the C standard, the consequences are undefined when you use Block_01 in File2.. But I think it's likely that it will be equivalent to giving it the same structure type declaration, and then using *(char *)(&Block_01).






      share|improve this answer


























        0












        0








        0







        The linker generally doesn't care about the size of object, just their addresses. The compiler reserves space in the object file that defines the object. In this case, the definition is in File1.c, which declares a structure containing two uint16, so it will most reserve at least 4 bytes.



        According to the C standard, the consequences are undefined when you use Block_01 in File2.. But I think it's likely that it will be equivalent to giving it the same structure type declaration, and then using *(char *)(&Block_01).






        share|improve this answer













        The linker generally doesn't care about the size of object, just their addresses. The compiler reserves space in the object file that defines the object. In this case, the definition is in File1.c, which declares a structure containing two uint16, so it will most reserve at least 4 bytes.



        According to the C standard, the consequences are undefined when you use Block_01 in File2.. But I think it's likely that it will be equivalent to giving it the same structure type declaration, and then using *(char *)(&Block_01).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 15:46









        BarmarBarmar

        423k35244346




        423k35244346






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272237%2fstructure-extern-with-different-type%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ