digitalmars.D.bugs - auto class Access Violation
- Kris (18/18) May 30 2004 auto class Scratch
- Walter (5/22) May 30 2004 good
- Kris (3/28) May 30 2004 Whoops! :-}
- Stewart Gordon (16/27) Jun 01 2004 I'd say the compiler's doing something totally wrong, namely accepting
auto class Scratch { char[4096] s; } private final void append () { auto Scratch scratch; test (scratch.s); } void test (char[] s) { snprintf (s, s.length, "foo"); } While trying to get around the "clear everything to zero" loop for stack allocations, I thought I'd try using an auto class. The assembly looked good (no loop at usage point) but it GPF'd at runtime ... note that this is a stripped down example. Am I doing something totally wrong here? - Kris
May 30 2004
"Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message news:c9c4c7$21o1$1 digitaldaemon.com...auto class Scratch { char[4096] s; } private final void append () { auto Scratch scratch; test (scratch.s); } void test (char[] s) { snprintf (s, s.length, "foo"); } While trying to get around the "clear everything to zero" loop for stack allocations, I thought I'd try using an auto class. The assembly lookedgood(no loop at usage point) but it GPF'd at runtime ... note that this is a stripped down example. Am I doing something totally wrong here?Yes. You never allocated an instance of Scratch: auto Scratch scratch = new Scratch();
May 30 2004
Whoops! :-} "Walter" <newshound digitalmars.com> wrote in message news:c9djvh$urc$2 digitaldaemon.com..."Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message news:c9c4c7$21o1$1 digitaldaemon.com...auto class Scratch { char[4096] s; } private final void append () { auto Scratch scratch; test (scratch.s); } void test (char[] s) { snprintf (s, s.length, "foo"); } While trying to get around the "clear everything to zero" loop for stack allocations, I thought I'd try using an auto class. The assembly lookedgood(no loop at usage point) but it GPF'd at runtime ... note that this is a stripped down example. Am I doing something totally wrong here?Yes. You never allocated an instance of Scratch: auto Scratch scratch = new Scratch();
May 30 2004
Kris wrote:auto class Scratch { char[4096] s; } private final void append () { auto Scratch scratch; test (scratch.s); }<snip>Am I doing something totally wrong here?I'd say the compiler's doing something totally wrong, namely accepting an auto declaration without initialisation. Since scratch isn't initialised, one cannot do anything with it. And since an auto can't be subsequently assigned to, scratch remains a useless identifier throughout its scope. Therefore it is effectively a null declaration. Hence the compiler should report an error. Of course, an auto variable can still be null, if it's initialised by something other than a constructor (more likely if the _class_ isn't auto, but not necessarily). Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Jun 01 2004