Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Structure Assignments

807578May 5 2004 — edited May 28 2004
Here is my question for Sun's C gurus:

------------------------------------------------------------------
I want to copy the contents of a structure into
another instance of the same structure.

Example:

struct mystruct
{
char field1[20];
char field2 [30];
int field3;
};

Given two instances of this structure:

struct mystruct a;
struct mystruct b;

Careful way to copy contents of a into b would be:

strcpy(b.field1,a.field1);
strcpy(b.field2,a.field2);
b.field3 = a.field3;

But I have tried this method:

b = a;

Compiled under our Sun OS, this works fine.

Questions: Am I justified in treating structures
as "true" datatypes, like ints, etc? Can I be confident
that doing a value assignment like that above
will always work? How portable is this? Is it part
of ANSI C?

I want to know if I should really avoid structure
assignment like this in an application that must
be fairly robust, and portable.

----------------------------------------------------------
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 25 2004
Added on May 5 2004
3 comments
89 views