public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Self-referring const array initialisation
@ 2004-04-15 10:04 Hamilton, Ian
  2004-04-15 13:27 ` llewelly
  2004-04-16 14:16 ` Undefined Referenced Aleksei Andevis
  0 siblings, 2 replies; 3+ messages in thread
From: Hamilton, Ian @ 2004-04-15 10:04 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

Hi there

Here is a test program to illustrate a problem in some code
I have inherited:

#include <stdio.h>

const int array1[5]=
{
  1,
  2,
  3,
  4,
  5
};

const int array2[5]=
{
  1,
  array2[0] + 1,
  array2[1] + 1,
  array2[2] + 1,
  array2[3] + 1,
};

int main()
{
  printf ("Array values:\n\n");
  printf("array1  array2\n");

  printf("  %i       %i\n", array1[0], array2[0]);
  printf("  %i       %i\n", array1[1], array2[1]);
  printf("  %i       %i\n", array1[2], array2[2]);
  printf("  %i       %i\n", array1[3], array2[3]);
  printf("  %i       %i\n", array1[4], array2[4]);
}


If I build and run this on a Sun/Sparc/Solaris system using
gcc version 2.95.2, I get the following output:

Array values:

array1  array2
  1       1
  2       2
  3       3
  4       4
  5       5


However, if I use gcc version 3.3.2, I get this output:

Array values:

array1  array2
  1       1
  2       1
  3       1
  4       1
  5       1


A bit of investigation with the debugger revealed that the
initialisation code is producing the initialised array on the
stack, then copying it to its normal position in RAM. Unfortunately,
the initialisation code is reading values from the array's normal
position in RAM, so reads a zero for the array elements already
initialised instead of the initialised value.

My question is whether this sort of self-reference is allowed by
the C and/or C++ standards. In other words, is this a compiler bug,
or a bug in the above code?

Cheers,
Ian.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Self-referring const array initialisation
  2004-04-15 10:04 Self-referring const array initialisation Hamilton, Ian
@ 2004-04-15 13:27 ` llewelly
  2004-04-16 14:16 ` Undefined Referenced Aleksei Andevis
  1 sibling, 0 replies; 3+ messages in thread
From: llewelly @ 2004-04-15 13:27 UTC (permalink / raw)
  To: Hamilton, Ian; +Cc: 'gcc-help@gcc.gnu.org'

"Hamilton, Ian" <Ian.Hamilton@gbr.xerox.com> writes:

> Hi there
> 
> Here is a test program to illustrate a problem in some code
> I have inherited:
> 
> #include <stdio.h>
> 
> const int array1[5]=
> {
>   1,
>   2,
>   3,
>   4,
>   5
> };
> 
> const int array2[5]=
> {
>   1,
>   array2[0] + 1,
>   array2[1] + 1,
>   array2[2] + 1,
>   array2[3] + 1,
> };
> 
> int main()
> {
>   printf ("Array values:\n\n");
>   printf("array1  array2\n");
> 
>   printf("  %i       %i\n", array1[0], array2[0]);
>   printf("  %i       %i\n", array1[1], array2[1]);
>   printf("  %i       %i\n", array1[2], array2[2]);
>   printf("  %i       %i\n", array1[3], array2[3]);
>   printf("  %i       %i\n", array1[4], array2[4]);
> }
> 
> 
> If I build and run this on a Sun/Sparc/Solaris system using
> gcc version 2.95.2, I get the following output:
> 
> Array values:
> 
> array1  array2
>   1       1
>   2       2
>   3       3
>   4       4
>   5       5
> 
> 
> However, if I use gcc version 3.3.2, I get this output:
> 
> Array values:
> 
> array1  array2
>   1       1
>   2       1
>   3       1
>   4       1
>   5       1

FWIW, on i386-freebsd5.2, gcc 3.4 release cannidate gives the same
    output as gcc 2.95.2 . So I think this bug is fixed in 3.4 (but it is
    still present in 3.3.3). I can't find the bug report, however.

[snip]
> My question is whether this sort of self-reference is allowed by
> the C and/or C++ standards. In other words, is this a compiler bug,
> or a bug in the above code?

I am nearly certain C++ allows this. I can't find anything in 8.5.1
    that disallows it.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Undefined Referenced
  2004-04-15 10:04 Self-referring const array initialisation Hamilton, Ian
  2004-04-15 13:27 ` llewelly
@ 2004-04-16 14:16 ` Aleksei Andevis
  1 sibling, 0 replies; 3+ messages in thread
From: Aleksei Andevis @ 2004-04-16 14:16 UTC (permalink / raw)
  To: gcc-help

Hello All!

Can you help me with explanation:

gcc 3.2 (mingw)

Folowing sources - which builded in DLL

in  header file
---------------------
calss CF1Variant
{
public
  CF1Variant& CF1Variant::operator=(CF1Variant const& var);
  CF1Variant& operator=(const CF1Reference& ref);
  CF1Variant& operator=(const CF1ConstReference& ref);
}

Library compiled and builded
but when I use in another source (another DLL ) 
    CF1Variant t1(tag);
    CF1Variant t2(tag);
    t1=t2;
compiled fine , but in Linking step
I have got follows error (???)
undefined reference to `CF1Variant::operator=(CF1Variant const&)'



Can you help me - how should string in def file for my CFVariant library
for I can check - is this operator properly esported ?


In present DEF file I CAN't seee any poits for this operator ....

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-04-16 14:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-15 10:04 Self-referring const array initialisation Hamilton, Ian
2004-04-15 13:27 ` llewelly
2004-04-16 14:16 ` Undefined Referenced Aleksei Andevis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).