[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4787: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4789: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4790: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4791: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
InsideQC Forums • View topic - Funny C Rules (And Low-Level Languages in general)

Funny C Rules (And Low-Level Languages in general)

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Re: Funny C Rules (And Low-Level Languages in general)

Postby Spike » Sat Apr 04, 2015 4:36 am

stdcall dates back to when there were multiple languages and compilers for native code... microsoft used it in the hope that it would give people less reasons to hate windows, and its been plaguing c/c++ users ever since. :P
I think windows has some special magic so that message handlers can use either convention without exploding, because if people can muck it up, then they will do so, and have done so. This doesn't mean that you should do so.

stdcall is nice because if you passed the wrong number of arguments, your whole program explodes...
using cdecl means you probably won't notice for years.
stdcall's symbol decorations that add @4 or whatever depending on the number of arguments help when you have dodgy function protypes all over the place. personally I use fastcall as a default calling convention in debug builds so stuff like this is blatent, its like stdcall but with the added illusion of extra speed!

win64 has only one calling convention. it'll ignore any stdcall/cdecl/fastcall markup (it might still warn though, for compat with 32bit code if its later compiled for that instead).
and 64bit linux/unix predates that with a different one (except for wine, anyway).
.
Spike
 
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Funny C Rules (And Low-Level Languages in general)

Postby Baker » Sat Apr 04, 2015 12:56 pm

Interesting. So multiple calling conventions is a "Windows things".
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Funny C Rules (And Low-Level Languages in general)

Postby frag.machine » Sat Apr 04, 2015 10:18 pm

Indeed.

http://blogs.msdn.com/b/oldnewthing/arc ... 48616.aspx

To be fair, according to one of the commenters in the link above, _fastcall was created by Borland to use with Delphi.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2120
Joined: Sat Nov 25, 2006 1:49 pm

Re: Funny C Rules (And Low-Level Languages in general)

Postby jitspoe » Sun Apr 05, 2015 8:06 am


jitspoe
 
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

Re: Funny C Rules (And Low-Level Languages in general)

Postby Baker » Wed Apr 08, 2015 1:06 am

If you are going to use #pragma message (I use it a lot), don't use the word "warning" in the text. #pragma message is awesome to remind you to revisit code because it prints when you compile.

#pragma message ("If we aren't reading from server every frame, this stuff will break ...") // A note I stuck in make myself aware of a weakness in client/server separation

The compiler may see the word "warning" and interpret it as being a compile warning:
Don't do: #pragma message ("This causes a warning")

yourbin.exe 0 error(s), 1 warning(s)
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Funny C Rules (And Low-Level Languages in general)

Postby mankrip » Mon Apr 20, 2015 11:54 am

Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
/ /
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Re: Funny C Rules (And Low-Level Languages in general)

Postby Baker » Mon Apr 20, 2015 5:27 pm

The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Funny C Rules (And Low-Level Languages in general)

Postby revelator » Tue Apr 21, 2015 9:42 am

while malloc and free are usable in C++ i guess new and delete would be a better choice :)
allthough if you need something like _aligned_malloc/_aligned_free you would probably have to write it yourself.
atleast gcc does not accept malloc without typecasts in C, looks like void * is not treated as a valid pointer so gcc barfs.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2605
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Funny C Rules (And Low-Level Languages in general)

Postby mankrip » Thu Apr 23, 2015 4:32 pm

Anyway, since my last post I made all malloc typecasts explicit already.

I do plan on moving on to C++ in the future, so that may help.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
/ /
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Re: Funny C Rules (And Low-Level Languages in general)

Postby mh » Thu Apr 23, 2015 10:47 pm

I think the C-like subset of C++ is just a flat-out better language than C. It's worthwhile just renaming your .c files to .cpp and getting a clean compile. You'll be surprised at the amount of nastiness that lurks behind valid C code. Having features like stronger type-safety and explicit forward declarations will just make you a better programmer (your code will be cleaner too!); you don't have to descend to the ninth circle of template insanity in order to write C++ code.

There are some other C++ features such as function overloading and optional parameters/default parameter values that make code nicer too. A lot of C fans who dismiss C++ seem to do so based on some of the more extreme examples of C++ code imaginable, and apparently without even having much knowledge of the language, assuming that you must write classes for everything and use templates wherever possible (I'm thinking of something like Linus Torvalds' rant about C++ here, where he really showed how ignorant he is of what he was talking about more than anything else; unfortunately people will read that crap and believe it). None of that is true; the C-like subset is quite lean and simple.

As a bonus you can now link to and use both C and C++ libraries without any contortions.

As for compile times: just use precompiled headers. Even with C you can get the compile time for something like FitzQuake down from 10+ seconds to under 1 second.
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Funny C Rules (And Low-Level Languages in general)

Postby mankrip » Thu Apr 23, 2015 11:45 pm

Getting a bit off-topic here, what confuses me the most in C++ are namespaces. Classes and such are fine, I've learned about them during the Java classes in college.

And a Java feature that I love is to be able to access a public variable of an object directly from the return of a statement that returns that object. My Java skills are rusted, but an example would be somewhat like
{
(guy = new player (teleport.getOrigin()) ).setName ("Quake Guy Jr.");
}
instead of this:
{
guy = new player (teleport.getOrigin());
guy.setName ("Quake Guy Jr.");
}
I don't remember specific examples of code where I used this, but it simplified my code design a lot by allowing me to use nameless objects.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
/ /
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Re: Funny C Rules (And Low-Level Languages in general)

Postby revelator » Fri Apr 24, 2015 2:18 am

namespaces are a bit like C structs grouping together a bunch of functions :)
a simple way to explain it when in C you do something like thispointer->thisfunction to access say typedef struct thispointer { char *thisfunction; }
a namespace works much the same way but it looks a little different see -> thispointer::thisfunction. One big difference is that you can do namespace thispointer { char *thisfunction = wtf; }
while a C struct does not allow that as far as i know.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2605
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Funny C Rules (And Low-Level Languages in general)

Postby Baker » Wed May 13, 2015 9:16 pm

Here's a fun one.

float bob = 494;

What is type of !!bob ?

Is it still a float? Or did it turn into an int? I'm guessing it's an int because it is a logical operation result like ( == )
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Funny C Rules (And Low-Level Languages in general)

Postby revelator » Sat May 16, 2015 11:43 pm

could probably be a float if bob = 494.0f; hehe but i get your meaning :)
actually 494.0f would be a double so whoops :P
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2605
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Funny C Rules (And Low-Level Languages in general)

Postby ericw » Sun May 17, 2015 1:41 am

ericw
 
Posts: 92
Joined: Sat Jan 18, 2014 2:11 am

PreviousNext

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest