Warning C4096: '__cdecl'

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
User avatar
webfreakz.nl
Director
Director
Posts: 627
Joined: 11 Aug 2005 08:22
Location: Localhost, 127.0.0.1, [The Netherlands: South Holland-> Westland]
Contact:

Warning C4096: '__cdecl'

Post by webfreakz.nl »

Here's my compile log:
--------------------Configuration: openttd - Win32 Release--------------------
Compiling...
ai.c
C:\$games\#ottd_source\ai\ai_event.h(23) : warning C4096: '__cdecl' must be used with '...'
dedicated_v.c
null_v.c
win32_v.c
Generating Code...
Compiling...
build.c
trolly.c
default.c
pathfinder.c
Generating Code...
Compiling...
airport.c
command.c
console.c
console_cmds.c
currency.c
depot.c
economy.c
engine.c
fileio.c
gfx.c
gfxinit.c
landscape.c
misc.c
network.c
newgrf.c
npf.c
oldloader.c
openttd.c
pathfind.c
pbs.c
Generating Code...
Compiling...
players.c
saveload.c
screenshot.c
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\zlib.h(1122) : warning C4096: '__cdecl' must be used with '...'
settings.c
signs.c
sound.c
sprite.c
strings.c
texteff.c
vehicle.c
vehicle_gui.c
viewport.c
waypoint.c
widget.c
win32.c
window.c
aircraft_gui.c
airport_gui.c
bridge_gui.c
dock_gui.c
Generating Code...
Compiling...
engine_gui.c
graph_gui.c
industry_gui.c
intro_gui.c
main_gui.c
misc_gui.c
music_gui.c
network_gui.c
news_gui.c
order_gui.c
player_gui.c
rail_gui.c
road_gui.c
roadveh_gui.c
settings_gui.c
ship_gui.c
smallmap_gui.c
station_gui.c
subsidy_gui.c
terraform_gui.c
Generating Code...
Compiling...
town_gui.c
train_gui.c
aircraft_cmd.c
clear_cmd.c
disaster_cmd.c
dummy_land.c
industry_cmd.c
misc_cmd.c
order_cmd.c
C:\$games\#ottd_source\ai/ai_event.h(25) : warning C4096: '__cdecl' must be used with '...'
rail_cmd.c
road_cmd.c
C:\$games\#ottd_source\ai/ai_event.h(25) : warning C4096: '__cdecl' must be used with '...'
roadveh_cmd.c
C:\$games\#ottd_source\ai/ai_event.h(25) : warning C4096: '__cdecl' must be used with '...'
ship_cmd.c
station_cmd.c
C:\$games\#ottd_source\ai/ai_event.h(25) : warning C4096: '__cdecl' must be used with '...'
town_cmd.c
train_cmd.c
tree_cmd.c
tunnelbridge_cmd.c
unmovable_cmd.c
water_cmd.c
Generating Code...
Compiling...
network_client.c
network_data.c
network_server.c
network_udp.c
Generating Code...
Linking...

openttd.exe - 0 error(s), 6 warning(s)
The error with zlib.h has always been there on my system but as everything kept working okay i didn't mind. But lately there was a new file added to the /trunk/ called 'ai_event.h' and when I compile again I get 5 more errors.
And they are all the same:

warning C4096: '__cdecl'

I could shrink my post a bit a only keep the relevant parts? Just let me know developers!
# Programming is like sex, one mistake and you have to support it for the rest of your life. (Michael Sinz)
MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Post by MeusH »

warning C4096: '__cdecl'
I have the same warning. Do you use MSVC6++?

But it is just a warning, not an error, continue your patching happily.
User avatar
Graphite
Engineer
Engineer
Posts: 84
Joined: 17 Nov 2005 20:56
Location: Netherlands
Contact:

Post by Graphite »

I use MSVC++ 6 myself and get the same six warnings. I found some info on the exact warning, but unfortunately I don't really have enough experience yet myself to figure out exactly what to do with it.
A computer scientist is someone who, when told to "Go to Hell," sees the "go to," rather than the destination, as harmful.
User avatar
webfreakz.nl
Director
Director
Posts: 627
Joined: 11 Aug 2005 08:22
Location: Localhost, 127.0.0.1, [The Netherlands: South Holland-> Westland]
Contact:

Post by webfreakz.nl »

Yes, I'm using MS VS6 (enterprise) :)

I know it's just nothing more than a warning, but it anoys me :?
# Programming is like sex, one mistake and you have to support it for the rest of your life. (Michael Sinz)
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

I would be happy to help, but it's windows related (I don't get it) and I have no idea what it means. Since it's a warning you should just try to ahead and see if it works. Since it works for the other platforms, odds are that it will work. Some warnings are critical and some are not important. Say for instance "mixed declaration and statements". That one works on gcc, but will produce an error on the MS compiler. If you are only building something for yourself and you are using gcc, it's not important. However it IS important if you plan to commit the code :wink:
User avatar
webfreakz.nl
Director
Director
Posts: 627
Joined: 11 Aug 2005 08:22
Location: Localhost, 127.0.0.1, [The Netherlands: South Holland-> Westland]
Contact:

Post by webfreakz.nl »

Bjarni wrote:I would be happy to help, but it's windows related (I don't get it) and I have no idea what it means. Since it's a warning you should just try to ahead and see if it works. Since it works for the other platforms, odds are that it will work. Some warnings are critical and some are not important. Say for instance "mixed declaration and statements". That one works on gcc, but will produce an error on the MS compiler. If you are only building something for yourself and you are using gcc, it's not important. However it IS important if you plan to commit the code :wink:
yeah, and what if I had 1734 warnings of these instead of 6 right now and I still links the programm without any error? :P

I mean... isn't it possible to make it compile WITHOUT those warnings?
# Programming is like sex, one mistake and you have to support it for the rest of your life. (Michael Sinz)
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

webfreakz.nl wrote:I mean... isn't it possible to make it compile WITHOUT those warnings?
it's always possible to compile without warnings, you just use a flag to tell it not to show warnings :P
To actually removing the cause of the warning, you will need to figure out why it's there. Try searching for that warning on google or something. That helped me to figure out the cause of a weird error once. Most often you are not the first one on earth to get a certain problem
User avatar
Graphite
Engineer
Engineer
Posts: 84
Joined: 17 Nov 2005 20:56
Location: Netherlands
Contact:

Post by Graphite »

I had a look at it and changed a few things and the warnings are gone atleast. The question is ofcourse whether this code will still compile correctly on other platforms and in other compilers. So if anyone feels a calling to test it, then go ahead :P

P.S. Does anyone know a way to only add certain files to a patch with TortoiseSVN? When I created this patch, I had to manually edit out any other changes I've made to the source, which might get annoying in the long run.
Attachments
fixcdeclwarnings3234.diff
Gets rid of the 5 __cdecl warnings in Visual C++ 6. (built against r3234)
(548 Bytes) Downloaded 320 times
A computer scientist is someone who, when told to "Go to Hell," sees the "go to," rather than the destination, as harmful.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

first of all, you should NEVER edit a diff file by hand. Odds are that it's not possible to apply (I think that is the case with this one). You could do as the rest of us do: have more than one copy of the source

As for the fix, I wonder about making it more like

Code: Select all

#define WIN__cdecl __cdecl
then the define should be called from the project file instead of the source file

Code: Select all

#ifndef WIN__cdecl
#define WIN__cdecl
#endif

extern void WIN__cdecl empty_function(PlayerID player, int event, ...);
This way it will use it for the compiler that needs it while it will not be defined as a string anywhere else and it will be replaced with an empty space
User avatar
Graphite
Engineer
Engineer
Posts: 84
Joined: 17 Nov 2005 20:56
Location: Netherlands
Contact:

Post by Graphite »

After editing it I tested it again and it seemed to work fine, but that might have just been because the patcher I use is more lenient than others so I'll make sure I make the changes in a clean checkout next time. Can I assume that the diff file didn't work for you based on your "I think that is the case with this one"?

Your suggestion has its merits, though I'm not sure whether it's really needed. As far as I can tell, functions with variable parameter-lists need to use the __cdecl calling convention. I think this holds for just about any C++ compiler, only most of them just do it implicitly, so it shouldn't harm anything to make it explicit instead.
A computer scientist is someone who, when told to "Go to Hell," sees the "go to," rather than the destination, as harmful.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

Graphite wrote:I think this holds for just about any C++ compiler, only most of them just do it implicitly, so it shouldn't harm anything to make it explicit instead.
err... OpenTTD is coded in C, not C++
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

A horrible patch.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
User avatar
webfreakz.nl
Director
Director
Posts: 627
Joined: 11 Aug 2005 08:22
Location: Localhost, 127.0.0.1, [The Netherlands: South Holland-> Westland]
Contact:

Post by webfreakz.nl »

Darkvater wrote:A horrible patch.
What's your solution then? :P
# Programming is like sex, one mistake and you have to support it for the rest of your life. (Michael Sinz)
User avatar
Graphite
Engineer
Engineer
Posts: 84
Joined: 17 Nov 2005 20:56
Location: Netherlands
Contact:

Post by Graphite »

Whoops... so it is... I've looked around the net and __cdecl seems to be a standard element of the C language though, so my earlier words should still hold.

I think that in general it's preferable to solve a problem in a simple uniform way (i.e. make the __cdecl explicit for all cases) than to solve it in a case-specific way (add it only for the win-version), since the code doesn't end up cluttered with case-specific code. It all depends on whether adding the __cdecl to the offending statements works on all platforms though. If not, then obviously the case distinction would have to be made to get rid of the warnings.
Darkvater wrote:A horrible patch.
Ah... that was posted while I was typing this. Could you explain why it is a horrible patch so that I may learn how to do better in the future? Constructive criticism is always more helpful than remarks like this...
A computer scientist is someone who, when told to "Go to Hell," sees the "go to," rather than the destination, as harmful.
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

look at revision 3236 :)

There is already a CDECL for MS compilers which we have added. Bjarni could've been more thorough as well, but his WIN_CDECL was on the right track. :)

I have added the ZLIB_WINAPI to stdafx.h cause stupid VS6 compiles when compiling screenshot.c (PNG) as well which links implicitely with zlib.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
User avatar
webfreakz.nl
Director
Director
Posts: 627
Joined: 11 Aug 2005 08:22
Location: Localhost, 127.0.0.1, [The Netherlands: South Holland-> Westland]
Contact:

Post by webfreakz.nl »

Thanks everyone!
No warnings anymore! 8)
Linking...

openttd.exe - 0 error(s), 0 warning(s)
# Programming is like sex, one mistake and you have to support it for the rest of your life. (Michael Sinz)
User avatar
Graphite
Engineer
Engineer
Posts: 84
Joined: 17 Nov 2005 20:56
Location: Netherlands
Contact:

Post by Graphite »

No fair... you put up revision 3236 after posting the message :wink:

Anyhow... I wasn't aware that there was already a CDECL declared. Probably because I'm still trying to get a feel for the complete openTTD code. It really would've helped if you had said that earlier though instead of just that it's horrible. The warnings are gone atleast, so in the end all is well :D
A computer scientist is someone who, when told to "Go to Hell," sees the "go to," rather than the destination, as harmful.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

Darkvater wrote:There is already a CDECL for MS compilers which we have added. Bjarni could've been more thorough as well, but his WIN_CDECL was on the right track. :)
never really cared for the windows specific code and it shows. I just read the diff and changed it to something that I could live with. I didn't actually open the source code to check this and I would not commit this one either as I know I'm not the windows guru :wink:
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 27 guests