#Window routine HELP!!!
6 messages in this thread
In my quest to learn C as I program, I'm having a bit of a problem. So far
I've got a bunch of windows open on a screen, all of them displaying the
little pictures that I want. My goal is to have a subroutine that spits out
the color values of each window. Here's what I'm trying to do.
struct Window *win1, *win2, *win3 [windows are opened, images shoved in,
etc.] Dump_Pixel(win1, 100, 200); /* window, width, height */
void Dump_Pixel(iff_win, x, y)
struct Window *iff_win;
int x,y;
{
int i,j;
for (j=0;j<y;j++) {
for (i=0;i<x;i++) {
printf ("Color is %d\n", ReadPixel (iff_win->RPort, x,y));
}
} }
Seems pretty straightforward. When I compile with SAS, I get error 72,
"External Item Attribute Mismatch" at the beginning of the function. This
suggests that I'm somehow munging the window pointer, but I'm damned if I
can figure out how! Any help is appreciated.
Loyd
It is actually, quite simple to fix. When SAS/C first sees the call to the
function before it is declared, it creates a dummy prototype for the
function. When it encounters the function, the attributes don't match. To
get around this, just declare a prototype for the function at the start of
the file. My recommendation for getting a better message for this is to
always use the -cf (check for Function prototypes) option. It will
complain where you first called the function.
Augh. I'm glad I asked, as I would have *never* caught that one. I
automatically create void prototypes at the start of the file, and then
forget about them! That sounds like it might be the solution.
Thanks!
Loyd
Steve,
I think your diagnosis of the problem is incorrect… I believe that the
problem is that you did not tell the compiler (via a prototype) that the
first arguement to the function was a window pointer and not an int.
If this is the problem, you should be able to fix it by adding a
prototype (I normally have all functions prototyped in a file that gets
included into all modules) for that function. For the timebeing, try
adding the line:
void Dump_Pixel(struct Window *iff_win, int x, int y);
.. right before the routine itself and see if that fixes it.
Keith
That looks like it! Thanks!
Loyd
Loyd,
You're going to hate yourself.
The first time the compiler sees Dump_Pixel() is before it's
declaration, and it assumes it's an integer function. When it gets to the
actual declaration, it finds it's a void function…thus the mis-match.
This can be remedied one of several ways, the quickest and dirtest
is to simply move the declaration of the function to above the point in
your code where it's called.
The "correct" way is to prototype it in a .h file, of if this is a
single module program…at the top of the program right after the includes.
Don