Page 1 of 1
learning C/C++
Posted: Thu Dec 26, 2002 2:07 pm
by SNeKKe
Hi everybody,
For the past few days, I've been studying the C++-language. The problem is that I use MS VC++ 6.
Now, I'd like to know if there are any important changes between writing code in MS VC++ and DJGPP.
If yes, which are these big changes?
Also, if you use MS VC++ 6, I don't think I should learn Win32 or MFC programming for OS dev, but do I need to know how to write code as a console app, is that sufficient for a simple kernel ?
Thank you all for reading
Tom
Re:learning C/C++
Posted: Thu Dec 26, 2002 2:46 pm
by jrfritz
You cannot use VC++ 6 for OSDev...not anything...but you can use it's IDE...
DJGPP and VC++ have some small syntax differences..(right?)...
Usually you'll find out the ones when you compile

see yourself...
Re:learning C/C++
Posted: Thu Dec 26, 2002 2:49 pm
by SNeKKe
I know it can't be used but I'm just learning it at this moment although it is going well.
Anyway, thanks for the advice cuz I was a little scared that the syntax was different.
Re:learning C/C++
Posted: Thu Dec 26, 2002 4:37 pm
by richie
One important difference between gcc and VC++ is that you must declare your local variables at the begin of the function. In VC++ it is possible to write the following code:
Code: Select all
//this code wouldn't work in gcc
// ...
void myStupidFunction(int var1,int var2)
{
int tmp;
tmp = var1 + var2;
// ...
//now we need a new variable
int tmp2;
tmp2 = tmp *5;
// ...
}
To make the code compilable under gcc and VC++ you should write the following code:
Code: Select all
//this code wouldn't work in gcc
// ...
void myStupidFunction(int var1,int var2)
{
//declare all local variables
int tmp;
int tmp2;
//here starts the executable part of the function
tmp = var1 + var2;
// ...
tmp2 = tmp *5;
// ...
}
Re:learning C/C++
Posted: Fri Dec 27, 2002 7:49 am
by pskyboy
Thats not true ritchie
I for one have variables littered all over the place and it works fine.
Peter
Re:learning C/C++
Posted: Fri Dec 27, 2002 9:34 am
by hanoi
erm...you CAN use VC++ for OS-Development since it's an compiler..I guess the moebius uses it(but i don't know).
You just must have something in your code to check out exe-header and this stuff..i dunno how to use it exactly(since i am not using it..)
FYI
Re:learning C/C++
Posted: Fri Dec 27, 2002 10:39 am
by pskyboy
Yeah i think you can use VC++6 to do OS work but its a real pain and much easy to use a GCC compiler. I have done a little on this but can't rember much. There is a way to turn off all the standard C librarys in MSDEV and then u have to use objdump which comes as a GCC bin util and strip of the exe header i think you strip of the first 512bytes but i can't rember. Theres a tutorial on this somewhere but i can't rember where it is. Anyone else know?
Peter
Re:learning C/C++
Posted: Fri Dec 27, 2002 12:05 pm
by richie
And it is true. I have checked out what pskyboy said and with my gcc-version(Version 2.95.2 in Suse Linux 7.0) it is not possible to declare a local variable after some executable code (like calling functions). Perhaps that is a difference between djgpp under DOS/Win32 and gcc under linux. But it may also be possible that newer gcc versions support this. Or it is only a option that is set under suse 7.0 by default and isn't set in pskyboy's system. Who knows? But if someone will get strange errors in gcc and is sure he doesn't have made any mistakes he should try to move his variable declarations at top of his functions.
By the way. pskyboy: What compiler and what version of this comiler do you use?
I'm not sure if gcc is a real ANSI-C-Compiler!
I think it's not very good to use VC++ for developing an OS. VC++ is good in programming Windows applications with MFC but in producing flat binaries it's not very useful. I read that someone wants to write his OS in QBasic. Of course that works but an OS is near to the hardware and so you should use a language that is near to the hardware. Some languages are better for OS (asm, C/C++) and other languages are better for high level programming (Java, VisualBasic, Perl). Although it is possible to write a CGI in asm or C it is easier to write it in a scripting language like Perl.
Re:learning C/C++
Posted: Sat Dec 28, 2002 3:39 pm
by K.J.
I think that Tim Robinson uses VC++ 6 with his OS, both the IDE and compiler.
K.J.
Re:learning C/C++
Posted: Sun Dec 29, 2002 4:27 pm
by Tim
I use the Visual Studio IDE but I don't use the compiler any more. I use Cygwin since I couldn't rely on everyone else having a copy of VC++. Also, gcc and binutils seem a lot more flexible (or it's easier to get them to do what you want).