Subject: Re: ISSUE #?? Proposal: const attribute for input params
From: Kevin Cameron x3251 (Kevin.Cameron@nsc.com)
Date: Thu Dec 05 2002 - 11:19:55 PST
----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 73
> From michael.rohleder@motorola.com Thu Dec 5 10:49:44 2002
>
> See the attached main.c and the resulting 'nm' result...
>
> Nuff said.
>
> -Michael
'Fraid not.
You used the Sun compiler, when I run it through g++ nm gives
the attached result (all the same). So we're both right (or
wrong) depending on the compiler :-)
Does your compiler work if you call them all "foo" - note neither
differentiate on return type wrt linking.
BTW, if you want to be able to link (C++) routines with const arguments
(and I agree it's a good idea) you probably want to vote for my
dynamic binding proposal - you would only need to write one binder
routine that understands the Sun C++ compiler's name mangling scheme
(likewise I could do g++).
Regards,
Kev.
>
> Kevin Cameron x3251 wrote:
>
> > > From michael.rohleder@motorola.com Wed Dec 4 05:43:10 2002
> > >
> > > Hi Kevin,
> > >
> > > I am amazed that you say this. Yes, "const" has no impact on linking in C,
> > > but I am far away from naming it therefore syntactic sugar.
> > > And in case of C++ it is part of the name mangling and therefore has even
> > > impact on linking!
> > >
> > > -Michael
> >
> > If "const" was actually part of C++ name mangling it would be quite happy since
> > it would be another reason for using C++ instead of C. Unfortunately it isn't
> > (I tried it out before the last e-mail):
> >
> > void foo(int bar);
> >
> > and
> >
> > void foo(const int bar);
> >
> > are considered the same wrt linking. The return type is not considered either, so
> >
> > int foo(int bar);
> >
> > is also the same.
> >
> > NB: even if an argument is declared "const", it is only advisory, you can cast
> > away the const (that's why it's syntactic sugar).
> >
> > Kev.
> >
> > > Kevin Cameron x3251 wrote:
> > >
> > > > "const" is syntactic sugar in C (and C++), it has no impact on linking. While I agree that it is good
> > > > to put it in example mappings in the LRM, there is no way to force users use "const" in their C code.
> > > >
> > > > Kev.
>
> --
>
> NOTE: The content of this message may contain personal views
> which are not neccessarily the views of Motorola, unless specifically stated.
----------
X-Sun-Data-Type: default
X-Sun-Data-Description: default
X-Sun-Data-Name: nm.txt
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 47
00000000 a *ABS*
000208ec ? _DYNAMIC
00020a78 b _END_
00020850 ? _GLOBAL_OFFSET_TABLE_
00020870 ? _PROCEDURE_LINKAGE_TABLE_
00010000 ? _START_
000209c0 ? __CTOR_END__
000209bc ? __CTOR_LIST__
000209c8 ? __DTOR_END__
000209c4 ? __DTOR_LIST__
000209cc ? __EH_FRAME_BEGIN__
000209cc ? __FRAME_BEGIN__
00020a58 ? __FRAME_END__
U __deregister_frame_info
0001078c t __do_global_ctors_aux
00010560 t __do_global_dtors_aux
U __register_frame_info
00020a5c ? _edata
00020a78 B _end
00020a74 B _environ
00010850 R _etext
U _exit
00010804 ? _fini
000107e8 ? _init
00010818 R _lib_version
000104e4 T _start
U atexit
000209b8 d completed.4
00020a74 W environ
U exit
00010618 t fini_dummy
00010678 T foo1(int)
000106ac T foo2(int)
000106e0 T foo3(int)
00010714 T foo4(int)
000209bc d force_to_data
000209bc d force_to_data
00010624 t frame_dummy
00010558 t gcc2_compiled.
00010784 t gcc2_compiled.
00010678 t gcc2_compiled.
000107dc t init_dummy
0001066c t init_dummy
00010748 T main
00020a5c b object.11
000209b4 d p.3
U printf
This archive was generated by hypermail 2b28 : Thu Dec 05 2002 - 11:21:28 PST