Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

03.01 - Q&A

  • You cannot reply to this topic
120 replies to this topic

#1 Teej   GDNet+   -  Reputation: 176

Like
Likes
Like

Posted 09 April 2001 - 10:36 AM

If there''s something about the C language that you don''t fully understand, then chances are you''re going to suffer for it somewhere down the line. Between myself and the rest of the members of this forum, no C language question will go unanswered for long. You''ll get the answer you need, and the forum will gain a nice collection of C language Q&As for the benefit of future readers. Like I''ve said before, "There''s no such thing as a stupid question". Teej

Sponsor:

#2 keltor   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 April 2001 - 11:18 AM

You can get Gimp for win32 (which is about 90-99% stable depending on your video card) from here.

It is equal to Photoshop in many ways, better in some, and it does have it''s own faults. But generally much better than PaintShop Pro and of course free.

#3 d00dzs   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 April 2001 - 11:46 AM

Hi, I could use a little help with pointers, linked lists and FILE I/O.

d00dzs

I turn pixels into gold.


#4 Mucman   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 April 2001 - 11:52 AM

I just finished a course on data structures where we did linkedlists via array/cursor, dynamic, recursive... shoot me a question and I might be able to answer it , as for pointers, here is a great tutorial!

http://pweb.netcom.com/~tjensen/ptr/pointers.htm

you got me on the file I/O though... I know dittily squat about that stuff , hope that helps.

"You won''t get wise with the sleep still in your eyes." - Neil Peart

#5 Narkster   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 April 2001 - 02:07 PM

Heya,

I was wondering if anyone on ths forum has tried to use the free compiler: LCC Win32. I have recompiled the Quake 3 source with this but I do not think it compiles C++ stuff. Any yays or nays about it?

L8R

-Nark

#6 khal   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 April 2001 - 04:40 PM

Alright, I''ve got a billion questions on *exactly* how C/C++ compilers work (and I understand some of my questions may be compiler specific).

I''m currently taking a class on assembly language for the Motorola 68HC12, and many of my questions will involve understanding memory. I''ve got a ton of them (though, I can only remember so many at once!) so, please be patient =)

Firstly, I was to make a few statements...and please correct them if I''m wrong!! These are some of the fundamentals which I judge situations on, and I''d like for them to be corrected first, if they need to be.

1) C/C++ passes all parameters by value by default. This involves allocating a new & separate memory address on the hardware stack (using a instruction similar to LEAS -2,SP (for say, and int) AFTER the calling routine. Afterwards, a value equal to the passed parameter is placed within that address on the stack. The stack is deallocated BEFORE the end of the subroutine, therefore destroying or deallocating the "variable" on the stack. The described above is a part of (if not all of, I''m not sure!) what we would call "function overhead" -- any, of course takes a few CPU cycles. If the function is called over & over, it would be a waste of CPU cycles -- which introduces inline, which I''ll ask about in a sec.

2) An exception to this rule is whenever C/C++ passes parameter of any type of object. This includes any non-C strings, prewritten classes. This is because an "object" is essentially a variable (of type long int? - for 16 bit addressing) that acts as a pointer to the first position in memory in which the object holds. In this case, does C/C++ allocate stack space for the pointer (ie, 2 bytes onto stack, LEAS -2,SP) and allow the value of the pointer to change within the subroutine - but *NOT* affecting the results after the close of the subroutine. Therefore, you have access to "permanently" change all values within the object; however, any changes to the pointer (changing "where the pointer points to") will not be affected after the function call? This runs into a lot of grey area for me, as my understanding of C/C++ is limited here. Please explain any misunderstandings I have of C/C++ as well as anything you can think of that adds to this discussion.

3) Finally, I''m wondering *exactly* what goes on as far as memory goes, CPU cycles, and differences between functions, in the following code...in the comment I put what *I* believe is going on...

Class Example {
...
};

Example SubA(Example ex1)
{
... // does not create a copy of entire object ex1, merely a copy of the pointer ex1, allows all access to public variables
}

Example SubB(const Example &ex1)
{
... // passes the object "by reference" and does not allow the change of the pointer ex1, however, still allows access to public variable INSIDE ex1
}

And finally...tell me why this code is valid:
Example SubC()
{
Example ex2 = new Example();
return ex2;
}
...with my understanding, the local variable ex2 should be deallocated prior to the subroutine actually "ending." For this reason, the address ex2 points to should be an unallocated, random place in memory. The only way that I can convince myself that this works is if return actually (a) allocates space on the hardware stack for retrieval after the subroutine ends, to hold the value of the object ex2. (b) acts somewhat like a RTS instruction in the 68HC12, where it physically *replaces* the machine code that the function call (from main, or parent routine) with a copy of ex2; however, this would require special preparation of the function call, so that there is enough space in the actual call & space from any parameters passes (usually placed after the mnemoic AS WELL AS any extra space needed, so that you would not rewrite or overwrite the next instruction. In such case, the return operator much calculate how many bytes to increment the PC counter (again, I''m refering to the Motorola chip when I should be trying to learn the Intel x86 chipset) by the proper amount to "skip" over this white space. This seems like an awful long winded way to do things, so some clarification is much MUCH appreciated!!

Anyway, sorry for the terribly long post...and thanks for your time...
~khal

---
~khal

#7 Mano3D   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 April 2001 - 11:43 PM

Help.. please this is driving me nuts.

Since the first time the board was up I have followed through all the posts and have had very little in the way of problems, but this has me stumped. If I compile one of the original files from Teej''s site I have no problems with the compile or running of the game. If I type the code from scratch using the same settings for the libraries and links etc. then the game compiles ok but when run comes up with (mostly) "DI_Init failed".

I have checked for spelling mistakes and all the usual stuff, I even thought I had corrupted something so I formatted the hard drive and re-installed everything with still the same results.

If anyone has any suggestions as I am at a loss and not very experienced at this, it would be much appreciated.

I am using Windows2000 and VC++ 6.0 with DX8

Thanx in advance.

#8 d00dzs   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 April 2001 - 12:41 AM

I don''t know your problem for sure but i can give you a advice.
When you are at a critical point of the program(Creation of objs or devices...) put a MessageBox(HWND, LPCSTR, LPCSTR, UINT) call (it creates a messagebox with custom message) where teej does the error checking.This way you might have an idea what is wrong.
Sorry the bad English.)

I turn pixels into gold!!

#9 bios10h   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 April 2001 - 03:55 AM

Hi,

I love this forum and I''ve followed it since the beginning.
So here I am for the second edition and I hope we are all gonna enjoy it.

Thanks a lot for your time Teej,
bios10h.

#10 Teej   GDNet+   -  Reputation: 176

Like
Likes
Like

Posted 10 April 2001 - 06:04 AM

d00dzs: Pointers is a pretty popular topic, and for good reason -- it''s one of the most powerful assets of the C language. If you''re patient, I''m sure that you''ll find an article on pointers sooner rather than later in 03.03 - Selected Language Topics. I can almost guarantee the same treatment with linked-lists and file I/O; both hot topics.

khal: I happen to also do some OS development now and again, and I''ve found a nice little document that illustrates compiled code and actual ASM instructions:

http://nondot.org/sabre/os/S1Booting/CompilingBinaryFilesUsingACompiler.pdf

As for your numerical questions:

1) The PDF file I''ve mentioned will be of help here. It looks at functions, parameters and pointers, and how they''re treated by the compiler.

2) If memory serves, a function is given the pointer on the stack and is free to alter the contents of any memory accessible via the pointer, but cannot change the pointer itself. After all, the pointer is merely a variable (4-byte on Win32) value. When the caller regains control, the original pointer value is still on the stack from the original function call.

3) SubA() receives a copy of Example, and therefore can''t affect the object externally -- your typical ''pass by value''. On the other hand, SubB() receives a pointer to the object and masquerades it as an actual object (by reference), but can''t alter anything because of the const restraint. Finally, the last function, SubC() works because the return value of a function is passed back to the caller via the stack. Once again, the PDF file link I''ve provided will give you a look at function parameters and return values.

Whew...

Mano3D: You''re a little premature in worrying about the template code -- It''s part of the Ladder series that may be up by the time you read this. In the meantime, it''s hard to diagnose the problem from here, but one thing comes to mind: do you have the following #define?


#define DIRECTINPUT_VERSION 0x0700


One thing that was blatently absent from the template code the first time around was any form of debugging facility, but I can assure you that this time it won''t be overlooked. In your particular case, I''d rewrite DI_Init() to allow the HRESULT value from all of those DI calls to be returned to the caller (Game_Initialize()) so that you can see the error code and look it up in the documentation.


Keep ''em coming...

Teej





#11 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 10 April 2001 - 01:41 PM

Mano3D,

I''m not exactly sure how you have your stuff set up, but one possible cause of the problem is simply not having "resource.bmp" or whatever the file was called in the same directory as the .exe file. You might want to check this out since it was a common problem when dealing with "DI_Init Failed" messages. I know several others had this problem, myself included, and the solution was simply putting the .exe and "resource.bmp" in the same directory. Hope this helps. Peace.

Blazeroni

#12 d00dzs   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 April 2001 - 01:53 PM

That Works for the DD_INIT problem not for DirectInput.

d00dzs



#13 Blazeroni   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 April 2001 - 06:28 PM

Oh, sorry. My mistake. =(

#14 Mano3D   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 April 2001 - 11:20 PM

Thanx to all for the response.

I have checked (double and triple) all of the #defines and #includes as well as the paths etc. I think the problem I have is more to do with my typing than anything else since all the example DX programs compile and run fine as do Teej''s, it''s just a case of tracking down the offending item. Since my last post I again tried inputting a new project from scratch (except the WinBase and Utils files) and this time everything was OK, but I still can''t find the problem in the previous attempts as they both appear to be identical, maybe it''s just a quirk of my system, I''m sure I''ll work it out somewhere down the line.

Thanx again.

P.S. The site''s great Teej, keep it coming.

#15 wulf   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 April 2001 - 03:12 AM

Teej,

I''ve written a simple calculator program in dos. It works and im thrilled about it I read your article about the standard source code in windows:

int apientry winmain (hinstance etc.)

But if I compile the same program with this code instead of int main() for dos. It gives me a syntax error on the first line of the code before the ''( sign. Am I missing something, besides the proper knowledge??? Maybe I need to include another *.h file than iostream????

here the complete first three lines of the code:

#include

int apientry winmain(hinstance hinstance, //error on this line
hinstance hprevinstance,
etc.

thanx for your time...



#16 georgix   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 April 2001 - 03:44 AM

Hoi Wulf,

Try including windows.h. It is most likely that your compiler chokes on the argument types (hinstance etc.).

Houdoe


Edited by - georgix on April 11, 2001 10:45:23 AM

#17 Teej   GDNet+   -  Reputation: 176

Like
Likes
Like

Posted 11 April 2001 - 06:43 AM

wulf: If your compiler is complaining, then it''s usually a syntactical error. Either you''re missing an #include (as georgix suggests -- you definitely need windows.h), or some other file. You''ll know if you''re missing an include if the compiler complains that it doesn''t understand a function, keyword, etc. Usually you can track this down by searching for the term in the online help, which directs you towards the proper #include file.

Now, if the linker is complaining, then you''re most likely missing a library file. Under Project|Settings|Link, you can see some information on what the IDE is using to prepare your program. My hunch is that you haven''t set up a project for the right type of program -- create a new Win32 Application Project and drop your source file(s) into the new directory. This way, the IDE knows how to build windows applications (i.e. what to link to).

One other comment: DOS and Windows programs aren''t compatible (except under special circumstances). Chances are that you''ll have to change the way your calculator program does its business by creating a window or dialog box and processing user events such as keyboard entry or mouse clicks. For example, you''re not going to have a DOS shell in a Windows application...

In a nutshell, Windows programs start as windows programs. They''re written differently because they have to behave differently. You''re going to need to learn Windows application programming, which is not in the scope of these tutorials...

Teej



#18 submonkey   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 April 2001 - 02:51 AM

Background: I have some procedural "programming" experience in 4GL''s, like VB and MS Access, and a fair amount of bourne-shell scripting, and very (extremely) limited C...

Also this is (I think) more an algorithm than a syntax question.

In addition to following this forum, I''m trying to write a text-based adventure-type game, and I''ve run into my first stumbling block...

Picture a 2-dimensional hex map with 1000 hex''s. I''d like them numbered starting at 0 and spiraling outward from the center. Given the number of a hex, how do I find the numbers of the 6 hex''s adjoining it?

I''ve beat my head against the wall trying to figure this out, and have a feeling I''m going to kick myself when I find out...

Thanks

#19 Diabolus   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 April 2001 - 10:37 AM

Hi,

I just want to know ask thing:
Can you really go into the code line by line when we do stuff for the first time.

I''m a newly graduate programmer and to be able to use code, I really need to know what it does, means and implies. . .
That''s mainly why I''m here anyway, as DX7 help files are poorly documented in that sense.
Just for now, I get really mixed up with those new data types. . . (liek LPDIRECTDRAW, HINSTANCE and such)they seem liek they''ve been typefed but I can''t find info on them anywhere. . . to me these are the basic things I need to nail down before I even consider starting writing code. Same thing for functions and objects. . .I really need a clear explanation about what an object contains and does before I use it, detailed info on parameters and returns for functions. . . .

Am I the only one lost about this stuff???
the gap between win32 and console programming (I only did the latter in school) looks huge to me.
The post on basic windows application was very nice, I need more of this.

On another note:
I bought me a DX7 intro book and started to read it, but I always get jammed at the same level: win32 programming. Thanks to whoever directed me to that tutorial it looks mighty fine and i''m gonna dive into it just now.


I hope thread was the right one to post this. . .
and many thanks Teej, you''re doing a great job!
I owe you a (B)

Ð!@ßأܧ

#20 asylum101   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 April 2001 - 01:06 PM

hey submonkey
i read your post and was thinking about your problem i think that you might look towards differant ways of numbering your hex map if your firm on your numbering route two definte things you would need to know would be the actual row number your hex resides in and its number in that row i am working on some code for you but i know there is a beter way to do it ill also try to come up with an alternative numbering scheme and some code for it i have also done some text adventures before and work on a mud curently feel free to email me darkdragon007607@msn.com





PARTNERS