Code: Select all
#ifndef __B_H__
#define __B_H__
const char *prt =" string1";
#endif
However using the following works fine,
Code: Select all
#ifndef __B_H__
#define __B_H__
const char prt[] =" string1";
#endif
TIA
Code: Select all
#ifndef __B_H__
#define __B_H__
const char *prt =" string1";
#endif
Code: Select all
#ifndef __B_H__
#define __B_H__
const char prt[] =" string1";
#endif
Code: Select all
#ifndef __B_H__
#define __B_H__
const char *prt =" value";
#endif
Code: Select all
#include "b.h"
int main()
{
return 0;
}
Code: Select all
#include "b.h"
int egFunc(void)
{
return 0;
}
g++ a.cpp b.cpp
/cygdrive/c/DOCUME~1/ABCDE~1/LOCALS~1/Temp/ccCyRYxR.o:b.cpp:(.data+0x0): multiple definition of `_prt'
/cygdrive/c/DOCUME~1/ABCDE~1/LOCALS~1/Temp/cciIrrJR.o:a.cpp:(.data+0x0): first defined here
collect2: ld returned 1 exit status
Code: Select all
$ objdump -t a_ptr.o
a_ptr.o: file format pe-i386
SYMBOL TABLE:
[ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x00000000 a.cpp
File
[ 2](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _main
[ 3](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .text
AUX scnlen 0x31 nreloc 2 nlnno 0
[ 5](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .data
AUX scnlen 0x4 nreloc 1 nlnno 0
[ 7](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .bss
AUX scnlen 0x0 nreloc 0 nlnno 0
[ 9](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .rdata
AUX scnlen 0x7 nreloc 0 nlnno 0
[ 11](sec 2)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 _prt
[ 12](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 1) 0x00000000 ___main
AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0
[ 14](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 __alloca
Code: Select all
$ objdump -t a_arr.o
a_arr.o: file format pe-i386
SYMBOL TABLE:
[ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x00000000 a.cpp
File
[ 2](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _main
[ 3](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 _prt
[ 4](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .text
AUX scnlen 0x31 nreloc 2 nlnno 0
[ 6](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .data
AUX scnlen 0x0 nreloc 0 nlnno 0
[ 8](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .bss
AUX scnlen 0x0 nreloc 0 nlnno 0
[ 10](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .rdata
AUX scnlen 0x7 nreloc 0 nlnno 0
[ 12](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 1) 0x00000000 ___main
AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0
[ 14](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 __alloca
Code: Select all
const char some_array[6] = {'h','e','l','l','o',0};
const char *ptr = some_array;
Code: Select all
const char array[6] = {'h','e','l','l','o',0};
Just wated to confirm this.Solar wrote:Hmmm... fun. I compiled a.cpp to a.o using either version of b.h, and objdump'ed them to find out what's up.
Code: Select all
$ objdump -t a_ptr.o a_ptr.o: file format pe-i386 SYMBOL TABLE: [ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x00000000 a.cpp File [ 2](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _main [ 3](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .text AUX scnlen 0x31 nreloc 2 nlnno 0 [ 5](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .data AUX scnlen 0x4 nreloc 1 nlnno 0 [ 7](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .bss AUX scnlen 0x0 nreloc 0 nlnno 0 [ 9](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .rdata AUX scnlen 0x7 nreloc 0 nlnno 0 [ 11](sec 2)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 _prt [ 12](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 1) 0x00000000 ___main AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0 [ 14](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 __alloca
As for how the difference is justified, I'm clueless. Which scares be quite somewhat, as I think this is some basics I should know...Code: Select all
$ objdump -t a_arr.o a_arr.o: file format pe-i386 SYMBOL TABLE: [ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x00000000 a.cpp File [ 2](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _main [ 3](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 _prt [ 4](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .text AUX scnlen 0x31 nreloc 2 nlnno 0 [ 6](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .data AUX scnlen 0x0 nreloc 0 nlnno 0 [ 8](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .bss AUX scnlen 0x0 nreloc 0 nlnno 0 [ 10](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .rdata AUX scnlen 0x7 nreloc 0 nlnno 0 [ 12](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 1) 0x00000000 ___main AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0 [ 14](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 __alloca