public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug java/19738] New: gcjh generates invalid class member floating-point initialisers
@ 2005-02-01  7:00 rmathew at gcc dot gnu dot org
  2005-02-01 11:20 ` [Bug java/19738] " rmathew at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: rmathew at gcc dot gnu dot org @ 2005-02-01  7:00 UTC (permalink / raw)
  To: java-prs

For floating-point (float/double) class
members that are initialised, gcjh generates invalid
C++ code.

See:

  http://gcc.gnu.org/ml/gcc/2005-01/msg01738.html

for the issue in general and:

  http://gcc.gnu.org/ml/gcc-patches/2005-02/msg00032.html

for how it affects GCJ.

-- 
           Summary: gcjh generates invalid class member floating-point
                    initialisers
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rmathew at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19738


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

* [Bug java/19738] gcjh generates invalid class member floating-point initialisers
  2005-02-01  7:00 [Bug java/19738] New: gcjh generates invalid class member floating-point initialisers rmathew at gcc dot gnu dot org
@ 2005-02-01 11:20 ` rmathew at gcc dot gnu dot org
  2005-02-01 12:36 ` giovannibajo at libero dot it
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rmathew at gcc dot gnu dot org @ 2005-02-01 11:20 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From rmathew at gcc dot gnu dot org  2005-02-01 11:19 -------
A patch to avoid this error is at:

  http://gcc.gnu.org/ml/java-patches/2005-q1/msg00255.html

Note that the correct way to initialise a 
const float is apparently:

  class Foo
  {
    static const float bar;
  }

  const float ::Foo::bar = 123.456f;

If gcjh were to be modified to generate
code like this in the headers, we get
multiple definition errors from the linker
when two or more files #include the
generated file.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-02-01 11:19:42
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19738


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

* [Bug java/19738] gcjh generates invalid class member floating-point initialisers
  2005-02-01  7:00 [Bug java/19738] New: gcjh generates invalid class member floating-point initialisers rmathew at gcc dot gnu dot org
  2005-02-01 11:20 ` [Bug java/19738] " rmathew at gcc dot gnu dot org
@ 2005-02-01 12:36 ` giovannibajo at libero dot it
  2005-02-01 13:01 ` rmathew at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: giovannibajo at libero dot it @ 2005-02-01 12:36 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From giovannibajo at libero dot it  2005-02-01 12:36 -------
Yes. Notice that also this code:

struct A
{
  static const int a = 45;
};

is invalid without a matching definition. That is, you need to provide a single 
definition of:

const int A::a;

which obviously cannot be put in a header file. If you wonder why you need a 
definition, consider what happens if some user code does "&A::a", which is of 
course legal. Or think that to load a floating point constant into the CPU we 
need to fetch it from memory (which address if you don't provide a definition?)

In fact, I personally use this to expose constants without linkage:

struct A {
   enum { a = 45 };
};

but with floating point numbers you are out of luck. 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19738


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

* [Bug java/19738] gcjh generates invalid class member floating-point initialisers
  2005-02-01  7:00 [Bug java/19738] New: gcjh generates invalid class member floating-point initialisers rmathew at gcc dot gnu dot org
  2005-02-01 11:20 ` [Bug java/19738] " rmathew at gcc dot gnu dot org
  2005-02-01 12:36 ` giovannibajo at libero dot it
@ 2005-02-01 13:01 ` rmathew at gcc dot gnu dot org
  2005-02-01 15:57 ` gdr at integrable-solutions dot net
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rmathew at gcc dot gnu dot org @ 2005-02-01 13:01 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From rmathew at gcc dot gnu dot org  2005-02-01 13:01 -------
(In reply to comment #2)
> Yes. Notice that also this code:
> 
> struct A
> {
>   static const int a = 45;
> };
> 
> is invalid without a matching definition. That is, you need to 
> provide a single definition of:
> 
> const int A::a;

Thanks, I understand this.

I was wondering why gcjh generates an explicit
(and incorrect for reals, as it turns out) initialisation
for a "final" Java field but not otherwise. That
is, given:

  static final int foo = 32;

  v/s

  static int bar = 42;

gcjh generates the initialiser only for "foo",
but not "bar".

In both cases, *someone* needs to initialise
these fields, right? Since these are generated
from Java classes, presumably the "Java side"
will initialise them - but then, why explicitly
write it out for "final" (const) fields?

This is what I attempted to suppress with my
patch in the first followup comment in this PR.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19738


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

* [Bug java/19738] gcjh generates invalid class member floating-point initialisers
  2005-02-01  7:00 [Bug java/19738] New: gcjh generates invalid class member floating-point initialisers rmathew at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2005-02-01 13:01 ` rmathew at gcc dot gnu dot org
@ 2005-02-01 15:57 ` gdr at integrable-solutions dot net
  2005-02-01 16:00 ` gdr at integrable-solutions dot net
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-02-01 15:57 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From gdr at integrable-solutions dot net  2005-02-01 15:57 -------
Subject: Re:  gcjh generates invalid class member floating-point initialisers

"rmathew at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| A patch to avoid this error is at:
| 
|   http://gcc.gnu.org/ml/java-patches/2005-q1/msg00255.html
| 
| Note that the correct way to initialise a 
| const float is apparently:
| 
|   class Foo
|   {
|     static const float bar;
|   }
| 
|   const float ::Foo::bar = 123.456f;
| 
| If gcjh were to be modified to generate
| code like this in the headers, we get
| multiple definition errors from the linker
| when two or more files #include the
| generated file.


Put the initializations (the real definition) in a .C file
(e.g. implementation file).  As someone said eight years ago, that
special rule is a misfeature.

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19738


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

* [Bug java/19738] gcjh generates invalid class member floating-point initialisers
  2005-02-01  7:00 [Bug java/19738] New: gcjh generates invalid class member floating-point initialisers rmathew at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2005-02-01 15:57 ` gdr at integrable-solutions dot net
@ 2005-02-01 16:00 ` gdr at integrable-solutions dot net
  2005-02-01 18:39 ` cvs-commit at gcc dot gnu dot org
  2005-02-02  5:34 ` rmathew at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-02-01 16:00 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From gdr at integrable-solutions dot net  2005-02-01 16:00 -------
Subject: Re:  gcjh generates invalid class member floating-point initialisers

"giovannibajo at libero dot it" <gcc-bugzilla@gcc.gnu.org> writes:

[...]

| In fact, I personally use this to expose constants without linkage:
| 
| struct A {
|    enum { a = 45 };
| };

agree.

| but with floating point numbers you are out of luck. 

Indeed.

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19738


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

* [Bug java/19738] gcjh generates invalid class member floating-point initialisers
  2005-02-01  7:00 [Bug java/19738] New: gcjh generates invalid class member floating-point initialisers rmathew at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2005-02-01 16:00 ` gdr at integrable-solutions dot net
@ 2005-02-01 18:39 ` cvs-commit at gcc dot gnu dot org
  2005-02-02  5:34 ` rmathew at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-02-01 18:39 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-02-01 18:38 -------
Subject: Bug 19738

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rmathew@gcc.gnu.org	2005-02-01 18:38:16

Modified files:
	gcc/java       : ChangeLog gjavah.c 

Log message:
	PR java/19738
	* gjavah.c (jni_print_float): Do not emit floating-point
	initialiser for a static final field.
	(jni_print_double): Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1540&r2=1.1541
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/gjavah.c.diff?cvsroot=gcc&r1=1.126&r2=1.127



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19738


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

* [Bug java/19738] gcjh generates invalid class member floating-point initialisers
  2005-02-01  7:00 [Bug java/19738] New: gcjh generates invalid class member floating-point initialisers rmathew at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2005-02-01 18:39 ` cvs-commit at gcc dot gnu dot org
@ 2005-02-02  5:34 ` rmathew at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: rmathew at gcc dot gnu dot org @ 2005-02-02  5:34 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From rmathew at gcc dot gnu dot org  2005-02-02 05:34 -------
I checked in the patch referred to in the second comment after
it was approved by Tom Tromey.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.0.0
            Version|unknown                     |4.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19738


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

end of thread, other threads:[~2005-02-02  5:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-01  7:00 [Bug java/19738] New: gcjh generates invalid class member floating-point initialisers rmathew at gcc dot gnu dot org
2005-02-01 11:20 ` [Bug java/19738] " rmathew at gcc dot gnu dot org
2005-02-01 12:36 ` giovannibajo at libero dot it
2005-02-01 13:01 ` rmathew at gcc dot gnu dot org
2005-02-01 15:57 ` gdr at integrable-solutions dot net
2005-02-01 16:00 ` gdr at integrable-solutions dot net
2005-02-01 18:39 ` cvs-commit at gcc dot gnu dot org
2005-02-02  5:34 ` rmathew at gcc dot gnu dot org

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).