[petsc-dev] Compiling C code with C compiler

Jack Poulson jack.poulson at gmail.com
Mon Apr 4 21:32:52 CDT 2011


On Mon, Apr 4, 2011 at 9:24 PM, Dmitry Karpeev <karpeev at mcs.anl.gov> wrote:

>
> struct _p_Mat {
>   PETSCHEADER(struct _MatOps);
>   PetscLayout            rmap,cmap;
>   ...
> }
> typedef struct _p_Mat *Mat;
> Mat A;
> Now ((PetscObject)A)->comm is kosher, because of the way C lays out the
> struct.
> I don't know whether C++ does the same (there is the issue of where it
> sticks the vtable, and I'm not sure what else).
> I imagine there will be no problem, since we've been compiling the PETSc C
> code with C++ compilers for a decade now,
> but I don't know whether the C++ standard guarantees that.  Jed is the only
> person I know that actually reads the standard
> (or maybe it's part of the ABI).
>
> Dmitry.
>

I would think that most compilers would not even use a vtable for C code
since there are no virtual functions and no class derivations. On the other
hand,  it is my understanding that the way vtables are handled is not in the
standard and is up to the compiler. Jed may know better even though he hates
C++.

Jack
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20110404/c1c90c5a/attachment.html>


More information about the petsc-dev mailing list