Re: Windows Assembly
- From: "T.M. Sommers" <tms@xxxxxx>
- Date: Fri, 16 Sep 2005 04:49:32 GMT
Richard Cooper wrote:
What kind of game/s are you interested in?
A 3D game with sound and networking.
Why is C a real pain? There are tutorials for game playing programs in C and even using C in a DirectX shell for games.
Well, I like it for the reasons I listed earlier.
Mostly what I don't like is GCC. It prints out all of these error messages which don't make a bit of sense, even after I figure out what I've done that it doesn't like. Should I do something as trivial as type "if (var1 == 12 and var2 == 14) {" then it starts complaining about every single line in the file rather than simply tell me that it doesn't know the word "and".
That is actually legal in C++.
Then there's the standard library. For some reason half of the functions like to return -1 on error, which is a real bitch once you've gotten into the habit of typing "unsigned" in front of everything.
Then break yourself of that bad habit. You can't really expect the C library, or any library, to conform to your personal preferences. You have to learn how it works, and use it that way.
Sometimes it's especially stupid, like in the case of functions that return a pointer. Pointers are unsigned.
Pointers are pointers, and should be declared as such.
Then every time I make a new function, I have to type a prototype for it at the top of the file, and every time I make a new global variable, that has to go at the top of the file too. We've had two-pass assemblers forever, why not a two-pass C compiler?
The C language requires that everything be declared before use. If you don't want to separately type function declarations, then define your functions before you call them.
My main concern is that my C code isn't going to be as reliable as my assembly code. It's easy to type something in C that looks like it will work right, but it doesn't. Like this:
if ( (pointer = mmap(this, that)) < 0 ) {
That comparision is always false, because pointers are unsigned, yet
Do you really think that an assembler would catch an error like that?
for some reason that's one time that GCC doesn't bother to print a warning.
You can make gcc display more warnings by using the -W and -Wall switches.
So I can write error checking code, assume it works, and never know better until the day comes that the code screws up because it failed to detect that error. Imagine if I were writing really important data to a file via that mmap. I'd lose it all when the program segfaulted trying to write data to 0xFFFFFFFF.
You can hardly blame C or even gcc if you use library functions incorrectly..
Also, memmove() somehow found a way to bypass my segmentation fault handler while I was doing direct VGA access in Linux, and that signal handler was vitally important to making sure the VGA mode was restored in the event of a program crash. I have no idea how memmove() did that, but I test it by putting a line like "volatile *crash = NULL; crash++" before the memmove() and after it. Before it the signal handler was called correctly, after it the signal handler was never called and the program just segfaulted. I'm left to wonder how many other mystery bugs there might be in my program like that. I didn't do anything wrong, and my code looks totally correct, yet the error handling isn't going to work like it's supposed to.
Your description of the problem is not entirely clear, but I find it highly unlikely that you have encountered a bug of such seriousness (and if you have, it is an OS issue, not a C issue, so switching to assembler is not a solution). It is much more likely that you are doing something wrong. Why not reduce the code to the bare minimum necessary to show the problem, and post it? If I had to guess, I would guess that you are not using a BSD signal() function, and are forgetting to reset the signal handler after catching the first signal. Also, be aware that signal handlers can do very little safely.
I like to write programs that detect errors and act appropriately, but because of the above two items, I don't know that I can do that in C.
Many people write lots of safe C code.
-- Thomas M. Sommers -- tms@xxxxxx -- AB2SB
.
- Follow-Ups:
- memmove crash
- From: Richard Cooper
- memmove crash
- References:
- Windows Assembly
- From: Richard Cooper
- Re: Windows Assembly
- From: JGCASEY
- Re: Windows Assembly
- From: Richard Cooper
- Windows Assembly
- Prev by Date: Re: Windows Assembly
- Next by Date: Re: Windows Assembly
- Previous by thread: Re: Windows Assembly
- Next by thread: memmove crash
- Index(es):
Relevant Pages
|