[Dune] Warnings about FieldVector::size

Jö Fahlke jorrit at jorrit.de
Tue Aug 16 20:02:31 CEST 2011


Am Tue, 16. Aug 2011, 19:26:36 +0200 schrieb Martin Nolte:
> Yes, I did mean the situation where the member is not defined. As far as I see
> it, defining it is not possible because
> (a) it is a tempalte and needs instantiation
> (b) it cannot be instantiated within the header, because this yields multiple
> definitions in multiple object files.

It will be automatically instantiated when it is used.  The automatic
instantiations will yield weak symbols, which will be merged when linking.
This is the same as with member functions of template classes; all members of
template classes are effectively inline.  There is no need for explicit
instantiation.

You can verify this if you try and run the program from my previous mail (of
course after inserting the definition for the size member into test.hh):
======================================================================
cd /tmp/ && g++ -Wall -g -O0 test.cc main.cc -o test && ./test
direct: 0x80488a0
via frob: 0x80488a0
======================================================================
As you can see, it doesn't matter wether you take the adress of A<1>::size
from main.o or test.o, you will get the same adress in both cases.

> As to taking the address, things are different. You're right, the compiler
> cannot take the address of an enum and, hence, won't do so. With a static
> member, the compiler may take the address, though. Consider the following
> (valid) situation:
> 
> void foo ( const size_t &s );
> 
> void bar ()
> {
>   foo( FieldVector< double, 2 >::size );
> }

OK, you are right in this regard.  So it is neccessary to define
FieldVector::size, but that is OK, as I have shown above.

Bye,
Jö.

-- 
Kiss a non-smoker; taste the difference.
-- fortune
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: Digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20110816/b6e9ee7b/attachment.sig>


More information about the Dune mailing list