www.digitalmars.com         C & C++   DMDScript  

c++ - [BUG] reversed subscript operator still not supported in C

reply "Matthew" <matthew stlsoft.org> writes:
char ch;
char *p = &ch;

0[p] = 'a';
Mar 26 2004
parent reply Ilya Minkov <minkov cs.tum.edu> writes:
Matthew schrieb:
 char ch;
 char *p = &ch;
 
 0[p] = 'a';
 

Oh, come on, do you really need it? I'm pretty much sure that this was Walter's conscious desision to disallow that, so pointing his nose into standard or just popping up from time to time would give you nothing. It seems that C standard defines subscript as addition, but Walter has made additional (!) effort to actually do a subscript out of it! -eye
Mar 26 2004
parent reply "Matthew" <matthew stlsoft.org> writes:
I have not idea what point you're making. The compiler has non-standard
behaviour. What more needs to be said?

"Ilya Minkov" <minkov cs.tum.edu> wrote in message
news:c418p9$1uaf$1 digitaldaemon.com...
 Matthew schrieb:
 char ch;
 char *p = &ch;

 0[p] = 'a';

Oh, come on, do you really need it? I'm pretty much sure that this was Walter's conscious desision to disallow that, so pointing his nose into standard or just popping up from time to time would give you nothing. It seems that C standard defines subscript as addition, but Walter has made additional (!) effort to actually do a subscript out of it! -eye

Mar 26 2004
parent reply Jan Knepper <jan smartsoft.us> writes:
Have you talked to Microsoft or Borland lately?



Matthew wrote:
 I have not idea what point you're making. The compiler has non-standard
 behaviour. What more needs to be said?

-- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org
Mar 26 2004
parent reply "Matthew" <matthew stlsoft.org> writes:
About what?

 Have you talked to Microsoft or Borland lately?



 Matthew wrote:
 I have not idea what point you're making. The compiler has non-standard
 behaviour. What more needs to be said?

-- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org

Mar 26 2004
parent reply gf <mz_y2k yahoo...com> writes:
"Matthew" <matthew stlsoft.org> wrote in
news:c41j5r$2fmp$1 digitaldaemon.com: 

 About what?

I guess it was sarcasm about DMC's non-standard behaviour. I agree with you, Matthew, this is non-standard - I've seen it writen in C++ : The Core Language - and, as far as I know, VC and BCC do allow this.
 Have you talked to Microsoft or Borland lately?

 Matthew wrote:
 I have not idea what point you're making. The compiler has
 non-standard behaviour. What more needs to be said?

-- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org


~/gnf.pt
Mar 26 2004
next sibling parent reply "Will Dean" <will nospam.demon.co.uk> writes:
"gf" <mz_y2k yahoo...com> wrote in message
news:Xns94B8E2E9992CDmzy2kyahoocom 63.105.9.61...
 I guess it was sarcasm about DMC's non-standard behaviour.
 I agree with you, Matthew, this is non-standard - I've seen it writen in
 C++ : The Core Language - and, as far as I know, VC and BCC do allow this.

And Walter has said that he's not working on some of the crashing bugs at the moment because he wants to get the standards compliance right first. So I expect he's more pleased to receive info about compliance bugs than he would be to get it about crashes... Will
Mar 26 2004
parent reply "Matthew" <matthew stlsoft.org> writes:
"Will Dean" <will nospam.demon.co.uk> wrote in message
news:c42c37$oah$1 digitaldaemon.com...
 "gf" <mz_y2k yahoo...com> wrote in message
 news:Xns94B8E2E9992CDmzy2kyahoocom 63.105.9.61...
 I guess it was sarcasm about DMC's non-standard behaviour.
 I agree with you, Matthew, this is non-standard - I've seen it writen in
 C++ : The Core Language - and, as far as I know, VC and BCC do allow


 And Walter has said that he's not working on some of the crashing bugs at
 the moment because he wants to get the standards compliance right first.

 So I expect he's more pleased to receive info about compliance bugs than

 would be to get it about crashes...

 Will

Ah, I understand the sarcasm now. Doh! It was "Borland and Microsoft have lots of non-standard behaviour, so why should Digital Mars care?". Well, I see no virtue in that position, and I would guess Walter doesn't either.
Mar 26 2004
parent Jan Knepper <jan smartsoft.us> writes:
Matthew wrote:
 Ah, I understand the sarcasm now. Doh! It was "Borland and Microsoft have
 lots of non-standard behaviour, so why should Digital Mars care?".

Oh...
 Well, I see no virtue in that position, and I would guess Walter doesn't
 either.

Walter probably will fix it sometime. You probably can fix it with a C-style cast too... -- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org
Mar 26 2004
prev sibling parent reply "Matthew" <matthew stlsoft.org> writes:
All the other Win32 compilers - Borland, Comeau, CodePlay, CodeWarrior, GCC,
Intel, MSVC, Watcom - work correctly in this regard.

The reason it's come up again is because I was expanding the compatibility
of the recls test programs to as many compilers as possible, and one of the
C clients uses my NUM_ELEMENTS macro, which uses the reversed subscript
form. <pretty-shameless-plug>The reasons for doing so are to be found in
Chapter 2 of "Imperfect C++", which should be out in
Sept/Oct</pretty-shameless-plug>

IMO, if something is non-standard, then that looks (and is) bad, no matter
how esoteric. The fact that it must be ridiculously simple to fix - since
this works for C++, it must be - then I cannot see any good reason why the
non-conformance would be dealt-with (Walter's ridiculous workload
notwithstanding, of course).

"gf" <mz_y2k yahoo...com> wrote in message
news:Xns94B8E2E9992CDmzy2kyahoocom 63.105.9.61...
 "Matthew" <matthew stlsoft.org> wrote in
 news:c41j5r$2fmp$1 digitaldaemon.com:

 About what?

I guess it was sarcasm about DMC's non-standard behaviour. I agree with you, Matthew, this is non-standard - I've seen it writen in C++ : The Core Language - and, as far as I know, VC and BCC do allow this.
 Have you talked to Microsoft or Borland lately?

 Matthew wrote:
 I have not idea what point you're making. The compiler has
 non-standard behaviour. What more needs to be said?

-- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org


~/gnf.pt

Mar 26 2004
parent reply Ilya Minkov <minkov cs.tum.edu> writes:
Matthew schrieb:
 All the other Win32 compilers - Borland, Comeau, CodePlay, CodeWarrior, GCC,
 Intel, MSVC, Watcom - work correctly in this regard.

Not an argument.
 The reason it's come up again is because I was expanding the compatibility
 of the recls test programs to as many compilers as possible, and one of the
 C clients uses my NUM_ELEMENTS macro, which uses the reversed subscript
 form. <pretty-shameless-plug>The reasons for doing so are to be found in
 Chapter 2 of "Imperfect C++", which should be out in
 Sept/Oct</pretty-shameless-plug>

Ah, you actually have some use for that! Interesting. Ok, this actually justifies it, although i cannot really imagine it too well. Say, does a simple addition not come into consideration? a[b] should standardly be the same as a+b, so that if one of them is a pointer, and another is an integer - no matter which - it works the same as pointer subscript if parenthesized correctly.
 IMO, if something is non-standard, then that looks (and is) bad, no matter
 how esoteric. The fact that it must be ridiculously simple to fix - since
 this works for C++, it must be - then I cannot see any good reason why the
 non-conformance would be dealt-with (Walter's ridiculous workload
 notwithstanding, of course).

Ah, it already works in C++? Then one of the behaviours is a bug. ;) -eye
Mar 27 2004
parent gf <mz_y2k yahoo...com> writes:
Ilya Minkov <minkov cs.tum.edu> wrote in
news:c43rh3$rh$1 digitaldaemon.com: 

 Matthew schrieb:
 All the other Win32 compilers - Borland, Comeau, CodePlay,
 CodeWarrior, GCC, Intel, MSVC, Watcom - work correctly in this
 regard. 

Not an argument.

Nope, it's a standard! :)
 The reason it's come up again is because I was expanding the
 compatibility of the recls test programs to as many compilers as
 possible, and one of the C clients uses my NUM_ELEMENTS macro, which
 uses the reversed subscript form. <pretty-shameless-plug>The reasons
 for doing so are to be found in Chapter 2 of "Imperfect C++", which
 should be out in Sept/Oct</pretty-shameless-plug>

Ah, you actually have some use for that! Interesting. Ok, this actually justifies it, although i cannot really imagine it too well. Say, does a simple addition not come into consideration? a[b] should standardly be the same as a+b, so that if one of them is a pointer, and another is an integer - no matter which - it works the same as pointer subscript if parenthesized correctly.

As they say in "C++: Core language" (where I saw this for the first time) "The array support provided by the language is mostly just convenient memory management and pointer arithmetic. Perhaps the best evidence is that brackets operator is, surprisingly, commutative. That is, if 'a' is an array, a[5] and 5[a] are interchangeable. The brackets are just a shorthand for pointer arithmetic: a[5] = *(a+5) = *(5+a) = 5[a]."
 IMO, if something is non-standard, then that looks (and is) bad, no
 matter how esoteric. The fact that it must be ridiculously simple to
 fix - since this works for C++, it must be - then I cannot see any
 good reason why the non-conformance would be dealt-with (Walter's
 ridiculous workload notwithstanding, of course).

Ah, it already works in C++? Then one of the behaviours is a bug. ;) -eye

~/gnf.pt
Mar 27 2004