473,398 Members | 2,389 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,398 software developers and data experts.

Arguments and Functions

Dear Group,

I am attempting to modify a portion of the source code for the global
illumination raytracer, RADIANCE. Specifically, I am trying to
implement a different ray/triangle intersection algorithm. My C
programming skills are laymen at best but I have successfully
implemented this algorithm for triangle polygons (the source code that
I am trying to modify is for a triangular mesh) previously. I have a
question concerning passing arguments on to functions. For all that I
have read and experienced, if there is a function that requires two
arguments, then those arguments must be with the function call (i.e.
function(arg1,arg2)) and the argument types must match the types in the
declared function. In the source code that I am modifying, I have come
across an instance wherein a function that is being called, which
requires two arguments, is being called without any arguments. In the
following file:

http://www.radiance-online.org/cgi-b...c/rt/o_mesh.c?
on line 167, it appears to me that the function mesh_hit is being
called but no arguments are being passed to it. The function mesh_hit
requires two arguments (oset, r). This code does successfully execute
but I do not know how it works. I have searched through all of my C
books and I have searched the web and usenet but I can not find any
answers. Can anyone explain this to me?

BTW

For anyone who wishes to tackle this issues, here is the address to
download ray.h (for the RAY type):

http://www.radiance-online.org/cgi-b.../src/rt/ray.h?

and object.h (for the OBJECT type):

http://www.radiance-online.org/cgi-b...ype=text/plain

Thanks

Marcus

Mar 10 '06 #1
12 1557
Marc said:

<snip>
http://www.radiance-online.org/cgi-b...c/rt/o_mesh.c?

on line 167, it appears to me that the function mesh_hit is being
called but no arguments are being passed to it.


You mean this?

rcont.hitf = mesh_hit;

If so, then no, this is not a function call. It is an assignment of a
function pointer value to a function pointer object.

In ray.h, you'll find the following structure member:

void (*hitf)(OBJECT *, struct ray *);

This is a pointer to a function that takes two parameters (of types OBJECT *
and struct ray *) and returns no value.

rcont.hitf = mesh_hit; means that you're pointing the hitf member of rcont
at the mesh_hit function. This does not involve a call to that function.
What it does imply, however, is that later on you can call the function
through the pointer, rather than by its actual name. The syntax for that
would be something like:

(*rcont.hitf)(&myobj, &myray);

although, perversely:

rcont.hitf(&myobj, &myray);

would also be legal. The exact syntax (ampersands, object names, and so on)
obviously depends on the types and names of the objects in question.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 10 '06 #2
Richard Heathfield <in*****@invalid.invalid> writes:
rcont.hitf = mesh_hit; means that you're pointing the hitf member of rcont
at the mesh_hit function. This does not involve a call to that function.
What it does imply, however, is that later on you can call the function
through the pointer, rather than by its actual name. The syntax for that
would be something like:

(*rcont.hitf)(&myobj, &myray);

although, perversely:

rcont.hitf(&myobj, &myray);

would also be legal. The exact syntax (ampersands, object names, and so on)
obviously depends on the types and names of the objects in question.


Considering the verbage used by the standard, it's the first one that
I would see more as a perversion. A function call is /always/ done
through a pointer-to-function; it's just that function designators are
implicitly converted to pointer-to-function.

The first invocation is a bit strange because, from the viewpoint of
the Standard, it's a pointer-to-function that, by virtue of your
dereference, is converted to function type and subsequently, since it
is not the operand of the & or sizeof operators, gets converted back
into a pointer-to-function before being called.

:-)
Mar 10 '06 #3
Micah Cowan said:
Richard Heathfield <in*****@invalid.invalid> writes:
The syntax
for that would be something like:

(*rcont.hitf)(&myobj, &myray);

although, perversely:

rcont.hitf(&myobj, &myray);

would also be legal. [...]


Considering the verbage used by the standard, it's the first one that
I would see more as a perversion.


<shrug> Can we agree to differ? I find that the * is most helpful in
deciphering the code on a first reading.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 10 '06 #4
On 2006-03-10, Micah Cowan <mi***@cowan.name> wrote:
Considering the verbage used by the standard, it's the first one that
I would see more as a perversion. A function call is /always/ done
through a pointer-to-function; it's just that function designators are
implicitly converted to pointer-to-function.


This seems to me along the same lines as saying that an array name is
converted to the pointer when used as the operand to [].

That is to say: It's technically correct... but is it art?
Mar 10 '06 #5
Jordan Abel wrote:
On 2006-03-10, Micah Cowan <mi***@cowan.name> wrote:
Considering the verbage used by the standard, it's the first one that
I would see more as a perversion. A function call is /always/ done
through a pointer-to-function; it's just that function designators are
implicitly converted to pointer-to-function.
This seems to me along the same lines as saying that an array name is
converted to the pointer when used as the operand to [].


(And as an operand to + and - and == and ...)
That is to say: It's technically correct... but is it art?


Does it matter if it's art?

--
Chris "truth is stranger than friction" Dollin
"Who do you serve, and who do you trust?"
Mar 10 '06 #6
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-10, Micah Cowan <mi***@cowan.name> wrote:
Considering the verbage used by the standard, it's the first one that
I would see more as a perversion. A function call is /always/ done
through a pointer-to-function; it's just that function designators are
implicitly converted to pointer-to-function.


This seems to me along the same lines as saying that an array name is
converted to the pointer when used as the operand to [].

That is to say: It's technically correct... but is it art?


The phrase "technically correct" is often used for facts that are
considered inconvenient for some reason.

IMHO, it's sufficient to say simply that it's correct. Yes, function
calls are usually used with function names, and array indexing is
usually used with array names, but understanding that they really work
with pointers is important to understanding the language.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 10 '06 #7
Jordan Abel <ra*******@gmail.com> writes:
That is to say: It's technically correct... but is it art?


I believe that Peter "Shaggy" Haywood can provide a relevant
quote here.
--
"I'm not here to convince idiots not to be stupid.
They won't listen anyway."
--Dann Corbit
Mar 10 '06 #8
Richard Heathfield <in*****@invalid.invalid> writes:
Micah Cowan said:
Richard Heathfield <in*****@invalid.invalid> writes:
The syntax
for that would be something like:

(*rcont.hitf)(&myobj, &myray);

although, perversely:

rcont.hitf(&myobj, &myray);

would also be legal. [...]


Considering the verbage used by the standard, it's the first one that
I would see more as a perversion.


<shrug> Can we agree to differ? I find that the * is most helpful in
deciphering the code on a first reading.


Hey, what do i care what you want to use? I can read either just fine,
and would be quite at home messing with someone's code that uses
either style.

I was only trying to point out that, from the Standard's point of
view, you're /always/ invoking with a function pointer, and never a
function type. That certainly doesn't mean anyone else needs to see it
that way. But it may mean that you'll need a bit more justification
before calling your latter example a "perversity". ;-)

-Micah
Mar 10 '06 #9
Jordan Abel <ra*******@gmail.com> writes:
On 2006-03-10, Micah Cowan <mi***@cowan.name> wrote:
Considering the verbage used by the standard, it's the first one that
I would see more as a perversion. A function call is /always/ done
through a pointer-to-function; it's just that function designators are
implicitly converted to pointer-to-function.


This seems to me along the same lines as saying that an array name is
converted to the pointer when used as the operand to [].


It's converted to a pointer always (except when an operand of & or
sizeof). You can't possibly tell me you've never used code like:

char ary[] = "string value";
char *p = ary; /* <--- */

even if you might prefer

char *p = &ary[0];

(as I frequently do).

The fact has a strong semantic meaning. The function -> function
pointer, despite the fact that it works the same way, may have less
impact on programming, since you nearly always are using them in
invocations, anyway. I was just trying to point out that RH had little
reason to call it a perversion, given the way it's discussed in the
Standard.

-Micah
Mar 10 '06 #10
Micah Cowan said:
But it may mean that you'll need a bit more justification
before calling your latter example a "perversity". ;-)


I presume I can get some on eBay?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 10 '06 #11
Richard Heathfield <in*****@invalid.invalid> writes:
Micah Cowan said:
But it may mean that you'll need a bit more justification
before calling your latter example a "perversity". ;-)


I presume I can get some on eBay?


I dunno... but TeX provides it quite well...
Mar 10 '06 #12
On Fri, 10 Mar 2006 19:19:08 +0000 (UTC), Richard Heathfield
<in*****@invalid.invalid> wrote:
Micah Cowan said:
But it may mean that you'll need a bit more justification
before calling your latter example a "perversity". ;-)


I presume I can get some on eBay?


I don't know about the justification, but, at least judging from the
spam I receive, you can certainly get the perversity. <GGG>

- David.Thompson1 at worldnet.att.net
Mar 20 '06 #13

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

Similar topics

9
by: Chuck Anderson | last post by:
I have a function with 7 inputs. The last three have default values. I want to call that function specifying the first four, skip two and then specify the last. I thought I could write this...
12
by: Joel | last post by:
Hi all, Forgive me if I've expressed the subject line ill. What I'm trying to do is to call a c++ function given the following: a. A function name. This would be used to fetch a list of...
7
by: A. Saksena | last post by:
Hi all, Is it possible to write a function or a macro in C++, which is capable of accepting any number of arguments. To give an example, the following should be possible: - ...
4
by: Noah | last post by:
I have a dictionary that I would like to expand to satisfy a function's agument list. I can used the ** syntax to pass a dictionary, but this only works if each key in the dictionary matches an...
6
by: Melkor Ainur | last post by:
Hello, I'm attempting to build an interpreter for a pascal-like language. Currently, I don't generate any assembly. Instead, I just build an abstract syntax tree representing what I've parsed...
16
by: Martin Jørgensen | last post by:
Hi, Problem: ======== Some of my output functions are beginning to take pretty many arguments... I mean.... We're talking about 10-15 arguments :-) So I thought to myself, perhaps this is...
4
by: mantrid | last post by:
Hello Hope you can help. I have been using the code below to move elenents around the page. This has worked fine until I put some arguments into the functions so I could use them in many places...
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
2
by: Alan | last post by:
I have a couple of questions about using a variable number of arguments in a function call (...). The context is that I have some mathematical functions I created. I currently pass them a pair of...
10
by: Armando Serrano Lombillo | last post by:
Why does Python give an error when I try to do this: Traceback (most recent call last): File "<pyshell#40>", line 1, in <module> len(object=) TypeError: len() takes no keyword arguments but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.