On Sat, Apr 17, 2010 at 10:39:56AM -0400, Byron Jeff wrote: > On Fri, Apr 16, 2010 at 09:51:28AM -0400, Isaac Marino Bavaresco wrote: > > Em 16/4/2010 11:22, Byron Jeff escreveu: > > > On Thu, Apr 15, 2010 at 11:23:21PM -0400, Justin Richards wrote: > > > Some snippage.... > > > Presuming that new1 is a struct. But to reiterate you can get both space > > > and a pointer to that space simply be declaring a single element array. > > > i.e. > > > > > > Temp_t new1[1]; > > > > > > Now new1 is a pointer to the allocated first element. No need to track two > > > different names. > > > > > > > You just replaced one annoyance by another, now you need to use > > "new1[0].Var00" and so on. > > No you don't. remember that the name new1 represents a pointer to a > structure. And fortunately C has an operator that takes a pointer to a > structure and accesses fields in the structure that the pointer points to. > It's called the arrow operator (->). So the above would be written: > > new1->Var00 > > And in my system, almost without exception structure access occurs through > a pointer, so the usage of the arrow operator is consistent both in a out > of functions with structs as parameters. So instead of: > > ////////////////////////////////////////////////// > void myfunc(Temp_p testme) > { > test->Var00 = 14; > } > > void main() > { > Temp_t myvar; > > myfunc(&myvar) > printf("myvar.Var00 = %d\n",myvar.Var00); > } > > ////////////////////////////////////////////////// > I would use: > > ////////////////////////////////////////////////// > void myfunc(Temp_p testme) > { > test->Var00 = 14; > } > > void main() > { > Temp_t myvar[0]; This is a mistake, it of course should be: Temp_t myvar[1]; I think I saw the 0 in the index access above and unconsciously copied it. BAJ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist