I''ve been experimenting with variable declarations, and I want to verify what my experimentation showed. It appears that implied declarations of variables, by assignment statement, must be physically before the first use of the variable, rather than logically, based on probe fire order. (The manual seems unclear to me.) For example: syscall::open:return { trace(self->file); } syscall::open:entry { self->file = copyinstr(arg0); } doesn''t work, because the compiler finds the trace before the assignment, and doesn''t know the type of self->file. Is this the way it works? Also, is there anything else besides an assignment statement that can imply the type of a variable (besides declaring it)? Thanks, Chip
Yes you''re correct, you need to assign or explicitly declare a variable before you can use it. As far as implying the type of variable you want other than assigning, you can either explicitly declare it, or you can also cast it to the type that you want. Noel On Jul 26, 2006, at 5:46 PM, Chip Bennett wrote:> I''ve been experimenting with variable declarations, and I want to > verify what my experimentation showed. > > It appears that implied declarations of variables, by assignment > statement, must be physically before the first use of the variable, > rather than logically, based on probe fire order. (The manual > seems unclear to me.) > > For example: > > syscall::open:return > { > trace(self->file); > } > syscall::open:entry > { > self->file = copyinstr(arg0); > } > > doesn''t work, because the compiler finds the trace before the > assignment, and doesn''t know the type of self->file. Is this the > way it works? > > Also, is there anything else besides an assignment statement that > can imply the type of a variable (besides declaring it)? > > Thanks, > Chip > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org
Noel Dellofano wrote:> Yes you''re correct, you need to assign or explicitly declare a > variable before you can use it. > > As far as implying the type of variable you want other than > assigning, you can either explicitly declare it, or you can also cast > it to the type that you want.I don''t think you can "initially" cast a variable to make the compiler know its type. The following also causes an error. syscall::open:return { trace((string)self->file); } syscall::open:entry { self->file = copyinstr(arg0); }> > > Noel > > On Jul 26, 2006, at 5:46 PM, Chip Bennett wrote: > >> I''ve been experimenting with variable declarations, and I want to >> verify what my experimentation showed. >> >> It appears that implied declarations of variables, by assignment >> statement, must be physically before the first use of the variable, >> rather than logically, based on probe fire order. (The manual seems >> unclear to me.) >> >> For example: >> >> syscall::open:return >> { >> trace(self->file); >> } >> syscall::open:entry >> { >> self->file = copyinstr(arg0); >> } >> >> doesn''t work, because the compiler finds the trace before the >> assignment, and doesn''t know the type of self->file. Is this the >> way it works? >> >> Also, is there anything else besides an assignment statement that >> can imply the type of a variable (besides declaring it)? >> >> Thanks, >> Chip >> _______________________________________________ >> dtrace-discuss mailing list >> dtrace-discuss at opensolaris.org > >