structure extern with different type
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
add a comment |
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
There's no type cast. You have the same variable declared with completely different types. It's a singlechar
inFile2.c
, but a structure inFile1.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
add a comment |
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
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
c struct linker compiler-warnings
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 singlechar
inFile2.c
, but a structure inFile1.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
add a comment |
There's no type cast. You have the same variable declared with completely different types. It's a singlechar
inFile2.c
, but a structure inFile1.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
add a comment |
3 Answers
3
active
oldest
votes
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
.
*(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
add a comment |
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
"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
add a comment |
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)
.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
.
*(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
add a comment |
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
.
*(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
add a comment |
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
.
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
.
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
add a comment |
*(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
add a comment |
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
"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
add a comment |
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
"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
add a comment |
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
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
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
add a comment |
"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
add a comment |
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)
.
add a comment |
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)
.
add a comment |
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)
.
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)
.
answered Nov 13 '18 at 15:46
BarmarBarmar
423k35244346
423k35244346
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
There's no type cast. You have the same variable declared with completely different types. It's a single
char
inFile2.c
, but a structure inFile1.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