Thread overview | ||||||
---|---|---|---|---|---|---|
|
May 30, 2004 auto class Access Violation | ||||
---|---|---|---|---|
| ||||
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 Re: auto class Access Violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kris | "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 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? Yes. You never allocated an instance of Scratch: auto Scratch scratch = new Scratch(); |
May 31, 2004 Re: auto class Access Violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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 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? > > Yes. You never allocated an instance of Scratch: > > auto Scratch scratch = new Scratch(); > > |
June 01, 2004 Re: auto class Access Violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kris | 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. |
Copyright © 1999-2021 by the D Language Foundation