Article View: comp.sys.atari.st
Article #39703Re: more on strncpy (was re: laser c question)
From: John Stanley
Date: Mon, 18 Dec 1989 12:49
Date: Mon, 18 Dec 1989 12:49
82 lines
3609 bytes
3609 bytes
[depeche@quiche.cs.mcgill.ca (Sam Alan EZUST) writes...]
[.. responding to email I sent to him ..]
> : Alternately, does Lazer C allow copying structures using a simple
> : assignment? <struct2> = <struct1>; If so, what I've ocassionaly used in
> : situations like yours is to define a struct containing the array and
> : moved copys of the array arround by just using assignments...
>
> that's a good idea. I should try it. I didn't think it was possible though,
> as struct names are just pointers to memory locations of data, just
> like arrays,
Nope. A struct name is the name of a structure. It is -not- a pointer
even though it has an address that you can obtain by using: &structname
(Note that the address you obtain (unless you cast it or store it into a
pointer of some other type) still "knows" that it's pointing to a struct
so if you use *(&structname) it references the original structure, not
just the 1st byte in the structure.
*(unsigned char *)(&structname) would give you the structures 1st byte...
> and you can address the 5th byte of a structure with
> *(structname+5) just like arrays.
Nope.... *(structname+5) is an illegal construct. You can't increment
a structure itself and contrary to your assumption, a structname is -not-
the same as a pointer to a structure.
On the other hand, ((&structname)+5) (which is different) would point
to a location 5 STRUCTURES higher in memory than &structname. In C, any
addition to a pointer is taken as increasing the pointer by (the value
added multiplied by the size of the object being pointed at (in this case
a structure)). This sometimes causes confuses because many people
normaly only deal with arrarys of characters (so the sizeof object == 1).
Example:
struct foo
{
int foo_1[32][100];
};
foocpy()
{
struct foo src, dst;
/* if your compiler allows structure assignment, */
/* the next line should copy an array 32 x 100 */
/* integers long with a single assignment... */
dst = src;
/* individual elements would be referenced as... */
src.foo_1[23][7] = 2619;
}
> you are exactly right. However, I got it working now via the brute-force
> loop-of-assign statements. If I can get dlibs installed properly on
> Laser C (and I am having trouble, as you will soon see in one of
> my messages posted on c-s-a-st which I posted today), I will then
> translate them all into memcpy's.
Good luck. You may still want to consider using struct assignments
since I've been told Lazer-C does support them...
> : .. although, it would be a real-good-idea if you posted a note on the
> : net mentioning that strncpy doesn't move <n> bytes so other beginning
> : programmers who see your message won't think that it's a correct
> : substitution....
>
> ok.. I shall. Thanks for your help/reply!!
You're welcome...
> --
> S. Alan Ezust depeche@calvin.cs.mcgill.ca
> McGill University Department of Computer Science - Montreal, Quebec, Canada
---
John Stanley <dynasoft!john@stag.UUCP>
Software Consultant / Dynasoft Systems
Technical Details
Message-ID:
<1989Dec18.124947.1535@stag.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!psuvax1!rutgers!uwvax!umn-d-ub!umn-cs!nis!pwcs!stag!daemonShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!psuvax1!rutgers!uwvax!umn-d-ub!umn-cs!nis!pwcs!stag!daemon From: john@dynasoft.UUCP (John Stanley) Newsgroups: comp.sys.atari.st Subject: Re: more on strncpy (was re: laser c question) Message-ID: <1989Dec18.124947.1535@stag.UUCP> Date: 18 Dec 89 12:49:47 GMT Sender: daemon@stag.UUCP (The devil himself) Organization: Mindtools ST Access Group Lines: 82