Am 14.05.2012 23:37, schrieb jacob navia:
> That could be done with a small interface of a few functions (all
> inlined). Yes, in those cases that would work, but imagine a simple
> container like the list container having 56 functions...
>
> The initialization would be very big. Will all compilers be so clever
> that they willnotice that those immediate constants are the same and
> create a single structure?
If it were just to create a const qualified compound literal, you are
right, not all compilers would notice the possibility to fold all of
these into one.
If it is an rvalue, there is no object to be allocated. All contents
of the rvalue can be constant propagated (I hope that's the correct
term and you see what I mean.) This is like doing
"A very very long string"[7]
*any* compiler should optimize that to the constant character 'v'.
> Or will they repeat all the initilizations with different immediate
> literals at each call? In any case that wikll repeat the code at
> each compilation unit. Maybe not a big deal if those initilaizations
> are short, what is not always the case.
if you have it as rvalues, there should never be an object allocated
for any of these, in particular if you then only select one of the
fields of that rvalue
>> (perl does such things for constants)
>
> Yes, for *constants* but not for a whole interface.
(I think in perl you can do that for "constants" in a very broad sense)
> Jens: your proposal *could* be a solution for special, small
> cases where the interface is small. Now, for longuish interfaces
> with quite a lot of functions, I see that much more difficult.
That's why I mentioned a possible extension of C that would be
"const qualified register variables in file scope".
That would be more appropriate as an extension to C than thinking of
introducing OO-like syntax. It would
- be simple to add, no existing code would break
- have a clear semantic
- add the missing feature of global, named constants for other types
than "int" (e.g double!)
- solve your problem much more elegantly that my crude macros with
their casting of compound literals.
Jens