In comp.lang.c++ jacobnavia <
ja...@jacob.remcomp.fr> wrote:
> 96 is not 512. You have made a mistake: you compiled the program with a
> C++ compiler. Use a C compiler instead.
Fine:
//-------------------------------------------------------------------
#include "ccl/intdlist.h"
#include <stdio.h>
int main()
{
printf("%zu %zu\n",
sizeof(struct INTERFACE_STRUCT_INTERNAL_NAME(int)),
sizeof(struct ITERATOR(int)));
return 0;
}
//-------------------------------------------------------------------
Compiled with "clang -O3", output:
512 112
> You say:
>
> <<
> Of course the C++ version is not only more memory-efficient, it's also
> technically speaking faster because every std::list method call is a
> direct function call
> >>
>
> The difference between a direct and an indirect call is just ONE MEMORY
> ACCESS. Does a single memory access make ANY difference at 2.7GB/second?
>
> Of course not.
It can have a difference in tight inner loops that are run millions of times.
C++ doesn't need this kind of indirection, and the optimization comes for
free, without you having to do anything for it.
> C offers the added flexibility (that you loose when the call is
> hard-wired like in C++) that you can change the call at run time if you
> want.
You say it like it's a C feature (rather than a feature of your library),
as if it were impossible in C++. After all, you didn't say "this library
offers the added flexibility". You said "C offers the added flexibility".
As if C++ didn't, if you implemented it like that.
> You say:
> <<
> in the C version each call has an
> additional level of indirection, and the compiler has no possibility
> of inlining.
> >>
>
> Of course the compiler could inline IF THE COMPILER WRITERS WANTED.
You first give the very reason why it can't be inlined (because, as you
said, the pointer could be changed at runtime to point somewhere else,
which effectively precludes inlining), and then you say that it could
be inlined if the compiler writers wanted. I don't think even you know
what you are talking about.
> But since C is not being developed anymore as a language
Oh, that's why the latest C standard is from 2011? That's ancient indeed.
Belongs to a museum.