From owner-freebsd-questions@FreeBSD.ORG Tue Mar 8 10:26:48 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 91DC916A4CE for ; Tue, 8 Mar 2005 10:26:48 +0000 (GMT) Received: from web51605.mail.yahoo.com (web51605.mail.yahoo.com [206.190.38.210]) by mx1.FreeBSD.org (Postfix) with SMTP id 2012943D46 for ; Tue, 8 Mar 2005 10:26:48 +0000 (GMT) (envelope-from jay2xra@yahoo.com) Received: (qmail 34790 invoked by uid 60001); 8 Mar 2005 10:26:47 -0000 Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; b=qGM1ZMT5a5uVf5jqI5e+HKKJd7pfyr/C8mW1EfEvWqGxwiZ5lcAQLjaRpHQ8YSMxqfrzTqmCP+xBEPIXMZ4wE2mNg5k/zUXWylT9lsclpIBBeU69Yu5pn3iiexcVc0uG3uljyHRZHhdQ1kw0b1L7g4LN/0rYlX6FNIFKJbDeVtc= ; Message-ID: <20050308102647.34788.qmail@web51605.mail.yahoo.com> Received: from [202.90.128.28] by web51605.mail.yahoo.com via HTTP; Tue, 08 Mar 2005 02:26:47 PST Date: Tue, 8 Mar 2005 02:26:47 -0800 (PST) From: Mark Jayson Alvarez To: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Is this a function or a structure???(once again, a mind-boggling example from Kernighan) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Mar 2005 10:26:48 -0000 Hi, On chapter 6 section 2 of The C Programming Language, the topic is Structures and Function. His very first example for this topic contains the lines of code: struct point makepoint(int x, int y) { struct point temp; temp.x = x; temp.y = y; return temp; } As I can understand it, he is trying to declare a structure of type "point", and the value of that structure will be the return value of the function "makepoint", or is it a function definition? Can anyone enlighten me if this is really a structure declaration or a function? If this is a structure, then there must be a definition outside the main for the function makepoint, right?Only that he didn't showed anything. But if this is already a function definition, like all of his examples before, perhaps a simple program should look like this #include<...> /* declare function makepoint */ /*i don't know how, do you?:) */ main() { /* call function make point and pass some arguments */ /* i'm not sure how to do this either.. help =( */ print("%d%d", newcreatedstruct.x,newlycreatedstruct.y) } struct point makepoint(int x, int y) { struct point temp; temp.x = x; temp.y = y; return temp; } My problem is how am i going to call the function makepoint. Why is there the word point in the above definition of makepoint. Another thing is the words temp.x and temp.y, if they are both members of structure temp, why didn't the author declared it first, instead he immediately initializing it to (x, y) I'm reading the "Notes To accompany The C Programming Language-> http://www.eskimo.com/~scs/cclass/krnotes/top.html" but it didn't help me that much in this topic. Perhaps you could. I have only 2 chapters left to read and I can't wait to reach the topics unix system calls, and sockets. But I don't want to leave this chapter floating in the air as if I've never read it. I really need all the help I can get. Thank you very much. Sincerely, jayson __________________________________ Celebrate Yahoo!'s 10th Birthday! Yahoo! Netrospective: 100 Moments of the Web http://birthday.yahoo.com/netrospective/