--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/c5f5ccc4-3267-442d-8cb2-de1ae103a38e%40isocpp.org.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/e7a864e9-a866-40d6-9688-95219dc34d92%40isocpp.org.
I think we should leave this macro alone and add new operator with different name that will be available everywhere.
And then optionally define `offsetof ` with use this new operator.
Doesn't the regular offsetof do something weird if the passed in type implements operator&and returns something evil?
I think we should leave this macro alone and add new operator with different name that will be available everywhere.
And then optionally define `offsetof ` with use this new operator.
The problem I'm talking about here is that if you have a `std.cstddef` module, without the ability to export macros, it cannot export anything which is compatible with `offsetof` usage. So even if we make an operator for this or empower member pointers or whatever, the existence of such a feature won't allow you to switch from `#include <cstddef>` to `import std.cstddef` without changing your code.
int A:: *int_in_A = &A::y; // just so we don't discuss arrays just now
A B:: *A_in_B = &B::a;
int B:: *int_in_B = int_in_A + A_in_B; // syntax TBD
On Thu, Mar 15, 2018 at 11:55 PM, Nicol Bolas <jmck...@gmail.com> wrote:The problem I'm talking about here is that if you have a `std.cstddef` module, without the ability to export macros, it cannot export anything which is compatible with `offsetof` usage. So even if we make an operator for this or empower member pointers or whatever, the existence of such a feature won't allow you to switch from `#include <cstddef>` to `import std.cstddef` without changing your code.
You just need to simultaneously modify C++ so that there is a built-in equivalent
to offsetof, and make offsetof a pre-defined macro that expands to that.
You just need to simultaneously modify C++ so that there is a built-in equivalent
to offsetof, and make offsetof a pre-defined macro that expands to that.
And if modules can't export macros, how will `import std.cstddef` give me access to that module?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1521219213.aWm8xxBS2X%40tjmaciei-mobl1.
On Fri, Mar 16, 2018 at 11:16 AM, Nicol Bolas <jmck...@gmail.com> wrote:You just need to simultaneously modify C++ so that there is a built-in equivalent
to offsetof, and make offsetof a pre-defined macro that expands to that.
And if modules can't export macros, how will `import std.cstddef` give me access to that module?
What module? I don't understand.
Let me try again:
- Change C++ so that there is a built-in version of offsetof under a different name, say __offsetof.
- __offsetof is available for use in all C++ code without any header or module needed, just as sizeof is.
- Also change C++ so that offsetof is a pre-defined macro that expands to __offsetof.
So... what happens with people's code that don't include <cstddef> or <stddef> that happens to use the `offsetof` identifier?
struct A { int x[10]; };
struct B { A a; };
int B::*number_5 = &B::a.x[5];
struct W { int x[10]; };
struct X { W w; };
struct Y { W w; };
struct Z : X, Y
{
void f();
};
void Z::f()
{
int *p = &Y::w.x[5];
*p = 4;
}
On Friday, March 16, 2018 at 8:13:44 AM UTC-7, Hyman Rosen wrote:struct A { int x[10]; };
struct B { A a; };
int B::*number_5 = &B::a.x[5];
Careful here: this is a breaking change. Consider this currently-legal code:
struct W { int x[10]; };
struct X { W w; };
struct Y { W w; };
struct Z : X, Y
{
void f();
};
void Z::f()
{
int *p = &Y::w.x[5];
*p = 4;
}
On Fri, Mar 16, 2018 at 2:56 PM, Myriachan <myri...@gmail.com> wrote:On Friday, March 16, 2018 at 8:13:44 AM UTC-7, Hyman Rosen wrote:struct A { int x[10]; };
struct B { A a; };
int B::*number_5 = &B::a.x[5];
Careful here: this is a breaking change. Consider this currently-legal code:
struct W { int x[10]; };
struct X { W w; };
struct Y { W w; };
struct Z : X, Y
{
void f();
};
void Z::f()
{
int *p = &Y::w.x[5];
*p = 4;
}
I swear, C++ drives me more crazy every time I look at it. Notice the obvious corollary to your code:
void Z::f()
{
int *p = &(Y::w.x[5]); // OK
int *q = & Y::w.x[5] ; // OK
W *r = &(Y::w) ; // OK
W *s = & Y::w ; // Error
}
C++ syntax is a horrible hodgepodge mess caused by too much "it would be nice if this meant that"
without any consideration of making everything globally consistent.
The first step would be to make a (quick) survey of C++ uses of offsetof --
that is, things that aren't just regular C code in C++ mode (think of Linux
kernel's struct list[1]).
The C standard library defines a large number of things that are macros. In the vast majority of cases, these are constants or functions, which can in C++ code be converted into `constexpr` variables or actual functions. For all intents and purposes, such constructs can be drop-in replacements for the C macros, which allows us to still work with them in a modular standard library that doesn't allow macros.
`offsetof` is a special case because it's not a function. Or at least, it's not a function that C++ at present allows you to write. Without reflection, there is no way to pass a typename or member variable as a function parameter. And while there are ways we can work around it, none of those ways would be drop-in replacements for `offsetof`; the user would have to change their code.
And even ignoring the non-drop-in part, there is currently no C++ replacement for `offsetof`. As modules moves forward, are there plans to resolve this issue and similar ones (beside the "let's get modules to export macros" plan)?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/c5f5ccc4-3267-442d-8cb2-de1ae103a38e%40isocpp.org.
On Sunday, 18 March 2018 08:15:20 PDT Richard Smith wrote:That's a good idea, but it would lead to no better code than what we have
> Looks like people in this thread have discussed pointers-to-members, but I
> didn't see anyone bring up what I think is the best option to replace
> offsetof (apologies if I missed it): a stdlib function that converts a
> pointer-to-data-member into an offset.
right now.
I'd still like to see more use-cases supported by the pointer to members,
composing them, inverting them (pointer to container), etc., so that we retain
type safety.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/304283527.crm4FIpuuk%40tjmaciei-mobl1.
I think I understand what your optimisation is trying to do here: support the
case where struct NON_SSO has tail padding, in which case the last byte in
struct SSO aliases no members in NON_SSO. Is that it?
If so, the code is dead in all modern platforms, since sizeof(size_t) ==
sizeof(void *) and ditto for alignof. So NON_SSO will never have tail padding
and it will be very hard for you to test this anywhere. Is this an
optimisation you really want to keep in your code?
Though I don't see any other way to test for padding at a specific position
aside from offsetof. That seems to be a legitimate use, though fragile and
dangerous.
I also think that your code in that condition is UB. You can't use t_sso and
t_non_sso at the same time -- only one member of a union can be active at a
time. Since this function is supposed to disable SSO, you must leave the
t_non_sso member of the union active at the end of your function, but the last
one it would have used is t_sso.
Your last_byte<T> type may be suffering from the same problem.