|
This thread is locked; no one can reply to it. |
1
2
|
4 assorted questions |
William Labbett
Member #4,486
March 2004
|
hi, 1. I was told a while ago something about not declaring functions that I define. void foobar() So I always give a prototype and the errors go away but I'd like to know if I'm missing something. 2. Flickering problem :- I've got a function draw_to_screen() which calls vsync() and blits the buffer to the screen. This worked well initially but since I started drawing more complicated stuff on the buffer I get flickering, even though only one function draws to the screen and vsync()'s always called before it. no flickering. But if I do :- I get the flickers. Please help. 3. (Numbskull C question) I've got a function defined as BITMAP * return c; Then I call it with bitmap_pointer = make_pattern(another_bitmap_pointer); ...and I get a compile error [Warning] assignment makes pointer from integer without a cast. When I run it all works like I wanted but I don't get what's wrong with the 4. Lastly. Just wondering :- I noticed that with allegro-4.0.0 if you call install_keyboard() after set_gfx_mode() it doesn't work properly. Might just be me but it had me confused for ages. Don't know if this is a known issue or not. Thanks. Will
|
CGamesPlay
Member #2,559
July 2002
|
Quote: Declaring and defining is wrong. Whoever said this doesn't know C. You're doing it right. For the second, something else is factoring in. Quote: ...and I get a compile error Forward declare the function and it will work. Also, warnings are not errors. -- Ryan Patterson - <http://cgamesplay.com/> |
William Labbett
Member #4,486
March 2004
|
Thanks ever-present CGamesPlay When you say forward declare the function - I'm sure what you mean.
|
Richard Phipps
Member #1,632
November 2001
|
2. Flickering: Unless you are using C++ then y is undefined and could be any random memory location each time the function is called. This could result in random numbers and flickering.. |
gnolam
Member #2,030
March 2002
|
Quote: allegro-4.0.0 Is bloody ancient. Use 4.2.1. -- |
William Labbett
Member #4,486
March 2004
|
Sorry - I wrote the code unclearly. y is an automatic in that function. The bitmaps get drawn properly just with flickering. I don't grok why a simple change like that (that's really the only difference although the function does contain other stuff) [edit] ...would cause flickering. BTW - well done for getting in EDGE magazine. Looking forward to your next release
|
CGamesPlay
Member #2,559
July 2002
|
Quote: When you say forward declare the function - I'm sure what you mean. I mean do what you want to do as per your first question. Declare it but don't define it. [append] Quote: ever-present CGamesPlay Thanks, I'm hoping for 21 000 posts before the year is out. -- Ryan Patterson - <http://cgamesplay.com/> |
William Labbett
Member #4,486
March 2004
|
You could get a few more if you can make me understand why the warning comes up -
|
CGamesPlay
Member #2,559
July 2002
|
Okay, in C, when you do this: void myFunc(void) { foo(); } The compiler assumes, unless it is told otherwise, that the prototype for foo() is this:int foo();(Keep in mind that in C this means the function accepts any number of arguments.) void myFunc(void) { BITMAP* another_bitmap_pointer; BITMAP* bitmap_pointer; another_bitmap_pointer = load_bitmap("base.bmp", NULL); bitmap_pointer = make_pattern(another_bitmap_pointer); destroy_bitmap(another_bitmap_pointer); destroy_bitmap(bitmap); } BITMAP* make_pattern(BITMAP* input) { BITMAP* c; c = create_bitmap(input->w, input->h); blit(input, c, 0, 0, 0, 0, c->w, c->h); return c; } What's happening? The compiler gets to the make_pattern line and can't find it declared any place else before. This is called 'implicit declaration', and it assumes the prototype is int make_pattern(). How do you fix it? Forward-declare the function:
[append] Quote: Unless you are using C++ then y is undefined and could be any random memory location each time the function is called. This could result in random numbers and flickering.. No, the only thing that the snippet told us about y is that is isn't a local variable Whether it's uninitialized is a different issue. -- Ryan Patterson - <http://cgamesplay.com/> |
William Labbett
Member #4,486
March 2004
|
Thanks for that reply CGamesPlay. I get what you're saying now. Trouble is I think I have declared the functions but I'll go home and check this. I didn't know you have to destroy local BITMAP pointers. Is this because although the pointer only exists during the call - the memory the BITMAP used up is still classed as unavailable ?
|
CGamesPlay
Member #2,559
July 2002
|
Quote: Trouble is I think I have declared the functions but I'll go home and check this. Make sure you declare them before the compiler gets to the function you use them in. Quote: Is this because although the pointer only exists during the call - the memory the BITMAP used up is still classed as unavailable ? Yes. -- Ryan Patterson - <http://cgamesplay.com/> |
William Labbett
Member #4,486
March 2004
|
Thanks for all the help. I'm off home now to get on with my project and put your help to use. See you later.
|
CGamesPlay
Member #2,559
July 2002
|
(a.k.a. bump) -- Ryan Patterson - <http://cgamesplay.com/> |
Richard Phipps
Member #1,632
November 2001
|
True. I forgot about global variables.. |
LennyLen
Member #5,313
December 2004
|
Quote: I forgot about global variables.. Not necessarily a bad thing.
|
ImLeftFooted
Member #3,935
October 2003
|
1) Already answered. |
CGamesPlay
Member #2,559
July 2002
|
Quote: Only problem I can see from your pasted code is the possibility of another_bitmap_pointer being defined as an int (instead of a BITMAP*). Not another one, because this is C so you can't overload, and even in C++ you can't overload by return type. See what I said about it above -- Ryan Patterson - <http://cgamesplay.com/> |
ImLeftFooted
Member #3,935
October 2003
|
Who said anything about overloading? I see a function 'make_pattern' which returns BITMAP*. I also see a variable 'c' of type BITMAP* that is returned. No type error here... |
CGamesPlay
Member #2,559
July 2002
|
Oh, I misunderstood. That isn't plausible because it said "assignment" and not "parameter". -- Ryan Patterson - <http://cgamesplay.com/> |
ImLeftFooted
Member #3,935
October 2003
|
Hm, on second thought, I believe you are right CGames. William: Try adding this right before you call the function and see if the error goes away:
|
CGamesPlay
Member #2,559
July 2002
|
Dude, read the thread. -- Ryan Patterson - <http://cgamesplay.com/> |
ImLeftFooted
Member #3,935
October 2003
|
Ok I read it all the way through this time. (its just so wordy ) Quote: Then I call it with bitmap_pointer = make_pattern(another_bitmap_pointer); ...and I get a compile error implies that bitmap_pointer = make_pattern(another_bitmap_pointer); causes the error. William: where is the error occuring? |
William Labbett
Member #4,486
March 2004
|
hi, first time back on the web for a while. Forward declaring the function did stop the warning coming up. I didn't know you could declare the same function in more than one source file.
|
CGamesPlay
Member #2,559
July 2002
|
Quote: I didn't know you could declare the same function in more than one source file. Remember, this is what header files do. A #include is just the compiler copying the named file in place of that line. -- Ryan Patterson - <http://cgamesplay.com/> |
William Labbett
Member #4,486
March 2004
|
thanks, but if you define some variable in a header included by more than one file you
|
|
1
2
|