473,411 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Struct assignment, historical question

I've got a history question, and several of you seem familiar with the history
of C, so perhaps someone knows.
The following:

#include<stdio.h>

struct checkit {
int a;
int b;
char c;
} wocka, tocka;

int main(void)
{
wocka.a = 10;
wocka.b = 20;
wocka.c = 'a';

printf("wocka = %d %d %c\n", wocka.a, wocka.b, wocka.c);

tocka = wocka;

printf("tocka = %d %d %c\n", tocka.a, tocka.b, tocka.c);

exit(0);
}

produces this for output:

wocka = 10 20 a
tocka = 10 20 a

That is, tocka = wocka; copied the entire contents of the structure.

But I'd swear that when I was working with C back in the '70's, this did not
work. To perform this copy, I had to do this:

tocka.a = wocka.a;
tocka.b = wocka.b;
tocka.c = wocka.c;

or

memcpy(&tocka, &wocka, sizeof(struct checkit));

Am I misremembering this, or was this actually the case? Or perhaps just a
problem with the Sun compiler I was using? I seem to have a vague recollection
of the original K&R saying that assignments wouldn't work, but likely would
some day.

- Bill
Jun 6 '06 #1
6 3199
On Mon, 5 Jun 2006 23:18:27 -0400, "William J. Leary Jr."
<Bi********@msn.com> wrote in comp.lang.c:
I've got a history question, and several of you seem familiar with the history
of C, so perhaps someone knows.
The following:

#include<stdio.h>

struct checkit {
int a;
int b;
char c;
} wocka, tocka;

int main(void)
{
wocka.a = 10;
wocka.b = 20;
wocka.c = 'a';

printf("wocka = %d %d %c\n", wocka.a, wocka.b, wocka.c);

tocka = wocka;

printf("tocka = %d %d %c\n", tocka.a, tocka.b, tocka.c);

exit(0);
}

produces this for output:

wocka = 10 20 a
tocka = 10 20 a

That is, tocka = wocka; copied the entire contents of the structure.

But I'd swear that when I was working with C back in the '70's, this did not
work. To perform this copy, I had to do this:

tocka.a = wocka.a;
tocka.b = wocka.b;
tocka.c = wocka.c;

or

memcpy(&tocka, &wocka, sizeof(struct checkit));

Am I misremembering this, or was this actually the case? Or perhaps just a
problem with the Sun compiler I was using? I seem to have a vague recollection
of the original K&R saying that assignments wouldn't work, but likely would
some day.

- Bill


The first 1978 edition of K&R mentioned that structure assignments and
the passing and returning of structures by value were common
extensions that were expected to become universal, but were not yet
allowed on all implementations.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jun 6 '06 #2

William J. Leary Jr. wrote:
I've got a history question, and several of you seem familiar with the history
of C, so perhaps someone knows.
[ ... cnip code ]
Am I misremembering this, or was this actually the case? Or perhaps just a
problem with the Sun compiler I was using? I seem to have a vague recollection
of the original K&R saying that assignments wouldn't work, but likely would
some day.


No. Struct assignment came in with the ANSI standard.
1. K&R 2: Preface: Paragraph 3: Line 1
2. K&R 2: Chapter 6: Paragraph 3: Line 1

Jun 6 '06 #3
> On Mon, 5 Jun 2006 23:18:27 -0400, "William J. Leary Jr."
<Bi********@msn.com> wrote in comp.lang.c:
I've got a history question, and several of you seem familiar with the history of C, so perhaps someone knows.
((..omitted..))
Am I misremembering this, or was this actually the case? Or perhaps just a
problem with the Sun compiler I was using? I seem to have a vague recollection of the original K&R saying that assignments wouldn't work, but likely would
some day.

"Jack Klein" <ja*******@spamcop.net> wrote in message
news:dr********************************@4ax.com... The first 1978 edition of K&R mentioned that structure assignments and
the passing and returning of structures by value were common
extensions that were expected to become universal, but were not yet
allowed on all implementations.
.... and ...

"Suman" <sk*****@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com... No. Struct assignment came in with the ANSI standard.
1. K&R 2: Preface: Paragraph 3: Line 1
2. K&R 2: Chapter 6: Paragraph 3: Line 1


When I remember where my 1978 K&R is, I'll look it up. But you've both just
settled and argument I was having here.

Thank you both.

- Bill
Jun 6 '06 #4

William J. Leary Jr. wrote:
[ snip ]
"Suman" <sk*****@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
No. Struct assignment came in with the ANSI standard.
1. K&R 2: Preface: Paragraph 3: Line 1
2. K&R 2: Chapter 6: Paragraph 3: Line 1


When I remember where my 1978 K&R is, I'll look it up. But you've both just
settled and argument I was having here.


Will you be able to find the lines I mentioned? I doubt. You'd
probably need one a good ten years younger :)

Jun 6 '06 #5

William J. Leary Jr. wrote:
I've got a history question, and several of you seem familiar with the history
of C, so perhaps someone knows.
The following:

#include<stdio.h>

struct checkit {
int a;
int b;
char c;
} wocka, tocka;

int main(void)
{
wocka.a = 10;
wocka.b = 20;
wocka.c = 'a';

printf("wocka = %d %d %c\n", wocka.a, wocka.b, wocka.c);

tocka = wocka;

printf("tocka = %d %d %c\n", tocka.a, tocka.b, tocka.c);

exit(0);
}

produces this for output:

wocka = 10 20 a
tocka = 10 20 a

That is, tocka = wocka; copied the entire contents of the structure.

But I'd swear that when I was working with C back in the '70's, this did not
work. To perform this copy, I had to do this:

tocka.a = wocka.a;
tocka.b = wocka.b;
tocka.c = wocka.c;

or

memcpy(&tocka, &wocka, sizeof(struct checkit));

Am I misremembering this, or was this actually the case? Or perhaps just a
problem with the Sun compiler I was using? I seem to have a vague recollection
of the original K&R saying that assignments wouldn't work, but likely would
some day.

Strictly speaking, K&R C had no structure assignment.
"Classic C" is a term used for pre-standard C, including structure
assignment, enumerations and void (but not void*).
C89 adopted void*, const and prototypes from C++.

I think that the following links are revelant:
http://cm.bell-labs.com/cm/cs/who/dmr/cchanges.pdf
More info on Dennis Ritchie web site : http://cm.bell-labs.com/who/dmr/
Interesting articles by Bjarne Stroustrup :
http://www.research.att.com/~bs/siblings_short.pdf
and http://www.research.att.com/~bs/sibling_rivalry.pdf

And a brief history of the C language by Dennis Ritchie :
http://cm.bell-labs.com/cm/cs/who/dmr/chist.html

Dennis' home page is full of interesting information on the C and B
languages and on UNIX.

Jun 6 '06 #6
Suman <sk*****@gmail.com> wrote:

No. Struct assignment came in with the ANSI standard.


On the contrary, struct parameters, return values, and assignment were
added to the Unix C compilers just about the time that K&R was actually
published (the "Recent Changes to C" paper noting them is dated Nov. 15,
1978), leading to a great deal of frustration many years later when
MS-DOS compilers appeared that implemented K&R exactly and thus didn't
support them.

-Larry Jones

He doesn't complain, but his self-righteousness sure gets on my nerves.
-- Calvin
Jun 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
10
by: David Rasmussen | last post by:
If I have this struct S { int arr; }; and I do this: S s1,s2;
20
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes)...
1
by: Michael Birkmose | last post by:
Hi everyone, I am in a situation where I need to instantiate a struct which has no tag name: struct some_struct { struct { int a; } embedded_member; };
2
by: Immo Birnbaum | last post by:
Hi, I'm trying to solve a programming lab assignment for my college C programming course, but as they taught us two semesters of Java before teaching us any C, I'm having problems with all the...
26
by: phoenix | last post by:
Hello, I've got a design question. I need to keep track of some variables and I am planning to put them inside a class or struct. Basically I'm talking about 10 bools, 20 ints and 2 arrays of...
28
by: WaterWalk | last post by:
Hi, I'm haunted by 2 questions about struct copy. Though I searched the net, but still in confusion. 1. Does struct assignment copies every member including array members? For example, struct...
5
by: Hallvard B Furuseth | last post by:
Does struct assignment copy padding bytes? Some compilers do, but I couldn't find anything in the standard which says they must. What I need is for any padding bytes to contan initialized values...
24
by: Grey Alien | last post by:
If I have the ff struct: struct A { unsigned int i; char s; } a, b; And use them in code like this:
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.