Re: gets() and "string" variable type

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete Lomax wrote:
> 
> Andy Drummond wrote:
> > 
> > What I would like to see addressed too is the possibility
> > of a type "string", which is a string of bytes rather than
> > a sequence of 32-bit words. The memory saving is significant,
> > and the possibility of strings containing non-characters is
> > completely removed.
> >
> > So - comments?
> The s[i] op is of critical importance, which I now know from practical
> experience,
> and supporting both 8-bit strings and 4-byte sequences would inevitably lead
> to an overhead of about 20%. Still want?
> 
> Regards,
> Pete
> PS [OT] Can someone explain the last line of this snippet from be_execute.e:
> 
>     case L_RHS_SUBS_CHECK:
> 	if (!IS_SEQUENCE(*(object_ptr)pc[1])) {
> 	    goto subsfail;
> 	}
> 	/* FALL THROUGH */
>     case L_RHS_SUBS: /* rhs subscript of a sequence */
> 	top = *(object_ptr)pc[2];  /* the subscript */
> 	obj_ptr = (object_ptr)SEQ_PTR(*(object_ptr)pc[1]);/* the sequence */
> 	if ((unsigned long)(top-1) >= ((s1_ptr)obj_ptr)->length) {
> 	    tpc = pc;
> 	    top = recover_rhs_subscript(top, (s1_ptr)obj_ptr);
> 	}
> 	top = (object)*(top + ((s1_ptr)obj_ptr)->base);
> 
> My grasp of C is limited and I do not actually understand how it knows to get
> "top" from "base+top*4" rather than just "base+top". Not that it does not seem
> logical, more "how does it know?"  Specifically, which parts of
> 
>    typedef long object;
>    typedef object *object_ptr;
> 
> are applied/applicable when and where? Is it the earlier *(object_ptr) or the
> latter (object)* or both or what?
Your question confuses me, but then again, so does the code.

To me, the last line of code is saying this:
top = -- self explanatory
(object) -- cast the next value as if it were an object type (the value of the
expression)
* -- the value pointed to by the expression of
(top +
((s1_ptr) -- cast the next value as an s1_ptr type
obj_ptr) -- the name of the structure pointer variable actually being used
->base); -- the member of the structure

Does that make more sense? I don't think there is any multiplication going on
(unless I misunderstand your question), just pointer dereferencing and casting.

I'm no C expert either, at least where it comes to very complicated expressions.
There are a lot of gotchas there. And I haven't yet studied the C source enough
to really understand what's going on in detail.

As for your typedef question, again I'm not sure what you are asking. The
typedef statement says that object_ptr is a pointer to an object (which is really
a long). The part where the code says (object)* is a cast to an object, not an
object pointer. The asterisk binds to the right, not the left, I believe.

Clear as mud? Or is that why we use Euphoria in the first place?

--
A complex system that works is invariably found to have evolved from a simple
system that works.
--John Gall's 15th law of Systemantics.

"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare

j.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu