[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/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/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 - Mundane C tricks ...

Mundane C tricks ...

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

Moderator: InsideQC Admins

Re: Mundane C tricks ...

Postby Baker » Mon Dec 10, 2012 12:54 am

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: Mundane C tricks ...

Postby taniwha » Mon Dec 10, 2012 2:34 am

Leave others their otherness.
http://quakeforge.net/
taniwha
 
Posts: 399
Joined: Thu Jan 14, 2010 7:11 am

Re: Mundane C tricks ...

Postby Baker » Mon Dec 10, 2012 4:56 am

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: Mundane C tricks ...

Postby taniwha » Mon Dec 10, 2012 7:38 am

Actually, names like that are very good: nothing quite like self-documenting code.

As for "da": dstring append. Thus, dasprintf is "sprintf to a dstring, but append it to what's already there". If you mean dag_t, that's "directed acyclic graph".

And the code itself: heh, close. Not linked lists, but sets. The sets are implemented via a bit array (but that's a private implementation detail :)). The code certainly code be implemented via linked lists (and the initial dag code did use lists), but using sets proved much easier (impossible to double-remove or double-add an item: no more looping through lists for removal, no worries about adding an item twice :)).

C's for-loops would have to be one of my favorite features of C. Any initializer, any test, any iterator. Using functions like I did in that code means I can change how sets are implemented and not worry about any code that uses them.

Alloca: hmm, well, I can think of a time: you're deep in the quake renderer somewhere and need a little bit of (variable sized) data. Since you're in a few loops deep, you don't want to use malloc (and friends). Hunk_TempAlloc is out of the question for some reason (does any engine other than QF have that one? I don't remember if I wrote it). alloca is your friend here: grab a chunk off the stack (very fast operation: two instructions on x86: sub esp,X; mov var,esp), work on the data, return from the function without worrying about freeing the code (exact same cost as having not used alloca: mov esp,ebp). Look in QF's libs/video/renderer/gl/gl_sky_clip.c for an example: very inner-loop. Or libs/video/renderer/r_light.c

For tool code: generally better to not use alloca. Image loaders: if you're in an inner-loop, you're doing it wrong :) (doesn't mean alloca isn't handy, though). Anyway, alloca is a powerful tool that should not be used lightly. Much like that weapon in Krull: if you're not sure, it's not time to use it.
Leave others their otherness.
http://quakeforge.net/
taniwha
 
Posts: 399
Joined: Thu Jan 14, 2010 7:11 am

Re: Mundane C tricks ...

Postby Spike » Mon Dec 10, 2012 11:02 am

in c99 you can use dynamically sized arrays. internally its an implicit alloca, but cleaner.
this avoids needing to make alloca part of the standard, of course.
alloca is much faster than malloc+free, and you don't need to care about freeing - which means it still gets freed if you longjmp out on say a Host_EndGame error or some such, but yes, you can still run out of memory, stack space is limited. makes it quite unsafe.
its awesome for small amounts though.
.
Spike
 
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Mundane C tricks ...

Postby mh » Mon Dec 10, 2012 11:02 pm

User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Mundane C tricks ...

Postby revelator » Tue Dec 11, 2012 1:14 am

Hmm though static analyzers warn about using alloca in loops because it can easily overflow the stack i seen no problems in Doom3 which does that a few places.

It does however scream use _malloca at me :P but then you also need to use freea so same story as malloc and free with the twitch that _malloca uses stack mem untill it overflows and then changes to heap mem.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2605
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Mundane C tricks ...

Postby Baker » Tue Dec 11, 2012 2:07 am

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: Mundane C tricks ...

Postby Baker » Tue Dec 11, 2012 4:16 am

Hmmm ... SDL apparently needs a different download for MinGW/GCC in Windows, a project can't use the VC sdl.lib / sdlmain.lib files, instead uses sdl.a and sdlmain.a files in a separate "For Mingw/Win32" download. Anyone know why this would be? [oddly enough SDL_mixer just uses the .lib]

I always like making a CodeBlocks project file since CodeBlocks/MinGW win installer can easily be installed on some other machine using a flash drive and only takes a couple of mins to do.
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: Mundane C tricks ...

Postby revelator » Tue Dec 11, 2012 11:57 am

MinGW uses a different naming convention for libs though it is possible to link with some msvc libs.
For dll import libraries it uses libname.dll.a and static libname.a one of the more obscure things is that the static libraries for mingw dont hold information on dependencies so you need to know what other libraries are needed. Thats because MinGW libraries actually arent libraries at all there an archive of object files (you can even open them with 7zip or winrar).

Some of the precompiled versions on the SDL site might not have import libraries for MinGW but mostly its pretty easy to recompile them for mingw :)
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2605
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Mundane C tricks ...

Postby mh » Wed Dec 12, 2012 12:36 am

User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Mundane C tricks ...

Postby taniwha » Wed Dec 12, 2012 3:08 am

Indeed, C++ certainly has its good bits, and even the STL has its uses, but oh, the error messages! The biggest legitimate gripe I know of is the lack of any form of standard for the ABI, and that might be history now.
Leave others their otherness.
http://quakeforge.net/
taniwha
 
Posts: 399
Joined: Thu Jan 14, 2010 7:11 am

Re: Mundane C tricks ...

Postby revelator » Wed Dec 12, 2012 3:57 am

C++ error messages make me cringe :twisted: C is usually pretty clear on where you might have done something it does not like on C++ though you get things like undefined vtables and other not so clear messages but it does indeed make certain operations easier when you get it right :)
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2605
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Mundane C tricks ...

Postby Baker » Wed Dec 12, 2012 6:42 am

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: Mundane C tricks ...

Postby Baker » Wed Dec 12, 2012 6:50 am

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

PreviousNext

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 2 guests