The strong typedef should introduce a new type and place it in the same
namespace as class-names.
So the proposal is something along the lines of
// Declare two types, say nothing of what they contain
strong typedef aType;
strong typedef aClass;
// Actually define the types
strong typedef int aType; // possibly allow ommitting strong here?
class aClass { };
Forward declarations are a stupid idea to begin with and should not be expanded on. The solution to this should be Modules.
On Saturday, May 17, 2014 10:36:44 AM UTC+12, Richard Smith wrote:On Fri, May 16, 2014 at 2:41 PM, Stack Machine <stackm...@hotmail.com> wrote:
Forward declarations are a stupid idea to begin with and should not be expanded on. The solution to this should be Modules.I generally agree, but with just a pinch of caution: forward declarations serve two purposes: reducing include dependencies and breaking cycles. Modules only helps with the first problem; we still need forward declarations for the second problem.How about:auto HANDLE;
void (HANDLE& x);Meaning: "Hey compiler HANDLE might be a class, struct, typedef, or whatever, but if you don't need to know, just go with it knowing it's not a spelling mistake."Is that what the OP wanted, and would it work?
Em sex 16 maio 2014, às 16:16:17, gmis...@gmail.com escreveu:
> How about:
>
> auto HANDLE;
> void (HANDLE& x);
>
> Meaning: "Hey compiler HANDLE might be a class, struct, typedef, or
> whatever, but if you don't need to know, just go with it knowing it's not a
> spelling mistake."
>
> Is that what the OP wanted, and would it work?
Can you enumerate what those cases "without knowing" you'd like the standard
to support?
Yes, you are right, and there are also function and member pointers for morerecent odd pointers so that kills the idea rather nicely.
2014-05-10 23:26 GMT+04:30 Magnus Fromreide <ma...@lysator.liu.se>:Yes, you are right, and there are also function and member pointers for morerecent odd pointers so that kills the idea rather nicely.I should respectfully object that this one is irrelevant. Normal pointers have the same size and representation - regarding the compilation platform.
And they are implicitly statically cast-able to void*; static_cast back from this result to the original type is also well-defined behavior.
I don't see how cycles are a problem at all. Other languages don't need forward declarations either. I'm sure they've come up with some viable solutions.
Am Samstag, 17. Mai 2014 00:36:44 UTC+2 schrieb Richard Smith:On Fri, May 16, 2014 at 2:41 PM, Stack Machine <stackm...@hotmail.com> wrote:
Forward declarations are a stupid idea to begin with and should not be expanded on. The solution to this should be Modules.I generally agree, but with just a pinch of caution: forward declarations serve two purposes: reducing include dependencies and breaking cycles. Modules only helps with the first problem; we still need forward declarations for the second problem.
--
On Sun, May 18, 2014 at 05:47:22PM +0430, Farid Mehrabi wrote:What about far, near and huge pointers on dos?
> 2014-05-10 23:26 GMT+04:30 Magnus Fromreide <ma...@lysator.liu.se>:
>
> > Yes, you are right, and there are also function and member pointers for
> > more
> > recent odd pointers so that kills the idea rather nicely.
> >
>
> I should respectfully object that this one is irrelevant. Normal pointers
> have the same size and representation - regarding the compilation platform.
> And they are implicitly statically cast-able to void*; static_cast back
> from this result to the original type is also well-defined behavior.
What about char pointers on word-addressable machines?
> Side note : Someone else used the term 'stupid'; whether or not some ideaYes. That was me, referring to my own idea; one can't use such language when
> looks practical to SB, the term used in that post does not sound
> respectful to - maybe only - me.
talking about the ideas of others.
I am sorry if I offended you.
On Sun, May 18, 2014 at 6:17 AM, Farid Mehrabi <farid....@gmail.com> wrote:
2014-05-10 23:26 GMT+04:30 Magnus Fromreide <ma...@lysator.liu.se>:Yes, you are right, and there are also function and member pointers for morerecent odd pointers so that kills the idea rather nicely.I should respectfully object that this one is irrelevant. Normal pointers have the same size and representation - regarding the compilation platform.This is true on common platforms, but not in general, and the standard has no such requirement.
And they are implicitly statically cast-able to void*; static_cast back from this result to the original type is also well-defined behavior.Yes, void* must be able to represent any object pointer, but some pointer types might be smaller than void*. For instance, on a word-addressable machine, the ABI might say that all class types have a size that is a multiple of one word, and all class pointers are the "normal" size for the machine, but char* and void* are represented as a pair of (word pointer, byte index).
2014-05-18 23:28 GMT+04:30 Richard Smith <ric...@metafoo.co.uk>:
This is true on common platforms, but not in general, and the standard has no such requirement.I used to consider this as the de facto standard.
And they are implicitly statically cast-able to void*; static_cast back from this result to the original type is also well-defined behavior.Yes, void* must be able to represent any object pointer, but some pointer types might be smaller than void*. For instance, on a word-addressable machine, the ABI might say that all class types have a size that is a multiple of one word, and all class pointers are the "normal" size for the machine, but char* and void* are represented as a pair of (word pointer, byte index).I need a concrete practical example please. PC mainframe micro??A machine + OS + tool chain + relative pointer-sizes .
Even if any platform with such design exists, the forward declared type can use pointers/references with void* layout. This is sub-optimal but yet easily implementable.
Em seg 19 maio 2014, às 19:38:55, Farid Mehrabi escreveu:> > Yes, void* must be able to represent any object pointer, but some pointer> > types might be smaller than void*. For instance, on a word-addressable> > machine, the ABI might say that all class types have a size that is a> > multiple of one word, and all class pointers are the "normal" size for the> > machine, but char* and void* are represented as a pair of (word pointer,> > byte index).>> I need a concrete practical example please. PC mainframe micro??> A machine + OS + tool chain + relative pointer-sizes .Let me throw another wrench in this discussion:even if you could determine the bitwise composition of the pointer orreference of this forward declared typename, you can't call a function with itand you can't use it in a template expansion. Some ABIs require encoding theaggregate type (class, struct, enum), and most ABIs will encode the original,non-typedef'ed name.
--
Em ter 20 maio 2014, às 17:21:57, Matthew Woehlke escreveu:> I'm not convinced the alleged ABI breakage is as much of an issue as is> being stated, since the ABI only changes for users of the feature.> Presumably these are either brand new ABI's with nothing old to break,> or else the library authors that choose to switch to using the new> feature know what they are doing.That only works if the new opaque definition exists for everyone and is usedeverywhere.That is, if we have:typename Foo;typename Bar::type;typename Baz;typename FooBar;Then *everyone* needs to see the typename, even those TUs that expand itlater:// required even if "typename Bar" wasn't previously seen,// due to typename Bar::typetypename struct Bar { typedef int type; };typename class Foo : public Bar {};typename class enum Baz { Frob = 0 };
typename typedef Foo FooBar;