🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2496

pointers for speed

#2496
From: Shaun Case
Date: Mon, 25 Feb 1991 21:13
61 lines
1975 bytes
I know that when you repeatedly access something like

foo.a.b.c.d[11].value

it is better to declare a (register) pointer, assign it the address
of foo.a.b.c.d[11].value, and do manipulations on that, since it
is faster.

However, I am dealing with a heavily nested structure, such as:

struct a {
	struct aa x;
	struct ab y;
	struct ac z;
	} le_struct;

typedef struct aa {
	struct one something;
	struct two nothing;
	struct three everything;
	struct four whatever;
	};


typedef struct one {
	char foo;
	char foo2;
	short blah;
	short blah2;
	};

And...

I want to access the various members of a.x.something (.foo, .foo2,
.blah, .blah2) quickly.  I have a function that I pass a pointer to 
type struct a, thus:

void do_stuff (struct *a ptr)
{}

and what I want to do is something like

register char *fastptr;

fastptr = &(ptr->x.something) 

and then access fastptr->foo, fastptr->foo2, etc.

I can't seem to get it to work.  Is this possible?
Help would be greatly appreciated, since the structure
I am working with is 6 levels deep at some points, and
I have to access every non-char element within it at least
once.  

( I think that from my foggy earlier days, what I am
trying to do is equivalent to Pascal's WITH feature,
in case what I was describing above isn't clear.  It's
been so long since I've used Pascal, tho, that I can
no longer be sure.  Thankfully.  :-)  )

// Shaun //
Technical Details
Message-ID: <1998@gold.gvg.tek.com>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!sdd.hp.com!spool.mu.edu!uunet!zephyr.ens.tek.com!gvgpsa!gold.gvg.tek.com

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!sdd.hp.com!spool.mu.edu!uunet!zephyr.ens.tek.com!gvgpsa!gold.gvg.tek.com
From: shaunc@gold.gvg.tek.com (Shaun Case)
Newsgroups: comp.std.c
Subject: pointers for speed
Message-ID: <1998@gold.gvg.tek.com>
Date: 25 Feb 91 21:13:26 GMT
Sender: shaunc@gold.gvg.tek.com
Organization: Grass Valley Group, Grass Valley, CA
Lines: 61