www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - auto class Access Violation

reply "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
        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
next sibling parent reply "Walter" <newshound digitalmars.com> writes:
"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 30 2004
parent "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
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();
May 30 2004
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
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