caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Question about warning message.
@ 2004-05-05 15:16 Claudio Trento
  2004-05-05 16:02 ` David Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Claudio Trento @ 2004-05-05 15:16 UTC (permalink / raw)
  To: caml-list

Hi,
my g++ compiler show me this warning:
  
    << warning: unused variable `int caml__dummy_n' >>

Here little lines of the function that generates this warning

....
extern "C"
CAMLprim value
foo(value n) try {
  CAMLparam1(n);  (perhaps something lacks here?!?)
  int nn = Int_val(n);
  ....
  ...

I don't know where is the problem! Please, who can help me?

Thanks

Claudio

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Question about warning message.
  2004-05-05 15:16 [Caml-list] Question about warning message Claudio Trento
@ 2004-05-05 16:02 ` David Brown
  2004-05-05 16:40   ` Roberto Bagnara
  2004-05-17 14:43   ` Damien Doligez
  2004-05-05 16:47 ` Xavier Leroy
  2004-05-05 20:46 ` Evan Martin
  2 siblings, 2 replies; 9+ messages in thread
From: David Brown @ 2004-05-05 16:02 UTC (permalink / raw)
  To: Claudio Trento; +Cc: caml-list

On Wed, May 05, 2004 at 05:16:06PM +0200, Claudio Trento wrote:
> Hi,
> my g++ compiler show me this warning:
>   
>     << warning: unused variable `int caml__dummy_n' >>

It is part of the construct the headers use to implement the
CAMLparam... macros.  Strictly it isn't necessary in C++, since you can
have declarations in the middle of a block, but then there would be
different constructs for C and C++.

BTW, what about having a
  (void) caml__dummy_##x;

at the end of the CAMLxparam... macros?  This does shut up the warning,
at least on gcc.

Dave

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Question about warning message.
  2004-05-05 16:02 ` David Brown
@ 2004-05-05 16:40   ` Roberto Bagnara
  2004-05-17 14:43   ` Damien Doligez
  1 sibling, 0 replies; 9+ messages in thread
From: Roberto Bagnara @ 2004-05-05 16:40 UTC (permalink / raw)
  To: David Brown; +Cc: Claudio Trento, caml-list, ppl-devel

David Brown wrote:
> On Wed, May 05, 2004 at 05:16:06PM +0200, Claudio Trento wrote:
>>my g++ compiler show me this warning:
>>  
>>    << warning: unused variable `int caml__dummy_n' >>
> 
> 
> It is part of the construct the headers use to implement the
> CAMLparam... macros.  Strictly it isn't necessary in C++, since you can
> have declarations in the middle of a block, but then there would be
> different constructs for C and C++.

That would not be a problem: most header files that must work
with both C and C++ do that.  For example, one thing that
the OCaml include files out to start and end with is

#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
} /* extern "C" */
#endif

Similar things based on the __cplusplus macro allows to obtain
header files that are 100% standard compliant with respect to
both C and C++.

> BTW, what about having a
>   (void) caml__dummy_##x;
> 
> at the end of the CAMLxparam... macros?  This does shut up the warning,
> at least on gcc.

This would do the trick, even though it is a bit of a hack.
What do the OCaml developers think?
Are they willing to accept patches to solve these problems?
Cheers,

     Roberto

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara@cs.unipr.it

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Question about warning message.
  2004-05-05 15:16 [Caml-list] Question about warning message Claudio Trento
  2004-05-05 16:02 ` David Brown
@ 2004-05-05 16:47 ` Xavier Leroy
  2004-05-05 19:22   ` Shawn Wagner
  2004-05-05 20:46 ` Evan Martin
  2 siblings, 1 reply; 9+ messages in thread
From: Xavier Leroy @ 2004-05-05 16:47 UTC (permalink / raw)
  To: Claudio Trento; +Cc: caml-list

> my g++ compiler show me this warning:
>     << warning: unused variable `int caml__dummy_n' >>
> Here little lines of the function that generates this warning
> ....
> extern "C"
> CAMLprim value
> foo(value n) try {
>   CAMLparam1(n);  (perhaps something lacks here?!?)
>
> I don't know where is the problem! Please, who can help me?

There's no problem with your code, and the warning is harmless.

It's just that the CAMLparam... macros used for GC root registration
expand to complicated C code that happens to trigger the "unused
variable" warning in gcc.  

David Brown suggest:

> BTW, what about having a
>   (void) caml__dummy_##x;
> at the end of the CAMLxparam... macros?  This does shut up the warning,
> at least on gcc.

Thanks for the suggestion.  That might do the job.  I'll let the
author of these macros (Damien Doligez) respond when he's back.

- Xavier Leroy

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Question about warning message.
  2004-05-05 16:47 ` Xavier Leroy
@ 2004-05-05 19:22   ` Shawn Wagner
  0 siblings, 0 replies; 9+ messages in thread
From: Shawn Wagner @ 2004-05-05 19:22 UTC (permalink / raw)
  To: caml-list

On Wed, May 05, 2004 at 06:47:15PM +0200, Xavier Leroy wrote:
> > my g++ compiler show me this warning:
> >     << warning: unused variable `int caml__dummy_n' >>
> > Here little lines of the function that generates this warning
> > ....
> > extern "C"
> > CAMLprim value
> > foo(value n) try {
> >   CAMLparam1(n);  (perhaps something lacks here?!?)
> >
> > I don't know where is the problem! Please, who can help me?
> 
> There's no problem with your code, and the warning is harmless.
> 
> It's just that the CAMLparam... macros used for GC root registration
> expand to complicated C code that happens to trigger the "unused
> variable" warning in gcc.  
> 
> David Brown suggest:
> 
> > BTW, what about having a
> >   (void) caml__dummy_##x;
> > at the end of the CAMLxparam... macros?  This does shut up the warning,
> > at least on gcc.
> 
> Thanks for the suggestion.  That might do the job.  I'll let the
> author of these macros (Damien Doligez) respond when he's back.
> 

A better solution for gcc (And, I think, icc) is to use the unused attribute
when the variable's declared.

Something like blah caml__dummy_##x __attribute__((__unused__));

-- 
Shawn Wagner
shawnw@speakeasy.org

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Question about warning message.
  2004-05-05 15:16 [Caml-list] Question about warning message Claudio Trento
  2004-05-05 16:02 ` David Brown
  2004-05-05 16:47 ` Xavier Leroy
@ 2004-05-05 20:46 ` Evan Martin
  2 siblings, 0 replies; 9+ messages in thread
From: Evan Martin @ 2004-05-05 20:46 UTC (permalink / raw)
  To: Claudio Trento; +Cc: caml-list

On Wed, May 05, 2004 at 05:16:06PM +0200, Claudio Trento wrote:
> Hi,
> my g++ compiler show me this warning:
>   
>     << warning: unused variable `int caml__dummy_n' >>

Now that you know it is harmless, you can disable the warning.

Set your compile flags to something like "-Wall -Wno-unused" to keep all
the other warnings enabled.

-- 
Evan Martin
martine@danga.com
http://neugierig.org

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Question about warning message.
  2004-05-05 16:02 ` David Brown
  2004-05-05 16:40   ` Roberto Bagnara
@ 2004-05-17 14:43   ` Damien Doligez
  2004-05-17 15:31     ` Olivier Andrieu
  2004-05-17 16:44     ` Roberto Bagnara
  1 sibling, 2 replies; 9+ messages in thread
From: Damien Doligez @ 2004-05-17 14:43 UTC (permalink / raw)
  To: caml-list

>> my g++ compiler show me this warning:
>>
>>     << warning: unused variable `int caml__dummy_n' >>

I'd consider this a design error in g++: the variable may be unused,
but its declaration is not useless because it has side effects.
Instead of a warning about unused variables, it should have a warning
about useless declarations.

> BTW, what about having a
>   (void) caml__dummy_##x;
>
> at the end of the CAMLxparam... macros?  This does shut up the warning,
> at least on gcc.

If we do that, the CAMLxparam macros can no longer be used in a
context of declarations.  These macros must include only definitions
because of the restrictive syntax of C.

I'll implement Shawn Wagner's suggestion, it is the cleanest way
to deal with this problem.

-- Damien

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Question about warning message.
  2004-05-17 14:43   ` Damien Doligez
@ 2004-05-17 15:31     ` Olivier Andrieu
  2004-05-17 16:44     ` Roberto Bagnara
  1 sibling, 0 replies; 9+ messages in thread
From: Olivier Andrieu @ 2004-05-17 15:31 UTC (permalink / raw)
  To: damien.doligez; +Cc: caml-list

 Damien Doligez [Mon, 17 May 2004]:
 > > BTW, what about having a
 > >   (void) caml__dummy_##x;
 > >
 > > at the end of the CAMLxparam... macros?  This does shut up the warning,
 > > at least on gcc.
 > 
 > If we do that, the CAMLxparam macros can no longer be used in a
 > context of declarations.  These macros must include only definitions
 > because of the restrictive syntax of C.

I think that the OP meant to add that line in the (...) that is part of
the definition. Something like this:

#define CAMLxparam1(x) \
  struct caml__roots_block caml__roots_##x; \
  int caml__dummy_##x = ( \
    (caml__roots_##x.next = local_roots), \
    (local_roots = &caml__roots_##x), \
    (caml__roots_##x.nitems = 1), \
    (caml__roots_##x.ntables = 1), \
    (caml__roots_##x.tables [0] = &x), \
    (void) caml__dummy_##x, \
    0)

Amazingly, this seems to "work" as well (work = silence gcc) :

#define CAMLxparam1(x) \
  struct caml__roots_block caml__roots_##x; \
  int caml__dummy_##x = ( \
    (caml__roots_##x.next = local_roots), \
    (local_roots = &caml__roots_##x), \
    (caml__roots_##x.nitems = 1), \
    (caml__roots_##x.ntables = 1), \
    (caml__roots_##x.tables [0] = &x), \
    caml__dummy_##x)

-- 
   Olivier

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Question about warning message.
  2004-05-17 14:43   ` Damien Doligez
  2004-05-17 15:31     ` Olivier Andrieu
@ 2004-05-17 16:44     ` Roberto Bagnara
  1 sibling, 0 replies; 9+ messages in thread
From: Roberto Bagnara @ 2004-05-17 16:44 UTC (permalink / raw)
  To: Damien Doligez; +Cc: caml-list

Damien Doligez wrote:
>>> my g++ compiler show me this warning:
>>>
>>>     << warning: unused variable `int caml__dummy_n' >>
> 
> I'll implement Shawn Wagner's suggestion, it is the cleanest way
> to deal with this problem.

Thanks!  These warnings are really annoying, and switching them off
globally is really not an option.
All the best,

     Roberto

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara@cs.unipr.it

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2004-05-17 16:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-05 15:16 [Caml-list] Question about warning message Claudio Trento
2004-05-05 16:02 ` David Brown
2004-05-05 16:40   ` Roberto Bagnara
2004-05-17 14:43   ` Damien Doligez
2004-05-17 15:31     ` Olivier Andrieu
2004-05-17 16:44     ` Roberto Bagnara
2004-05-05 16:47 ` Xavier Leroy
2004-05-05 19:22   ` Shawn Wagner
2004-05-05 20:46 ` Evan Martin

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 NNTP newsgroup(s).