• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Is there even a point to C/C++ in Windows?

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Chris_F

Member
Joined
Jun 30, 2003
Location
Columbus, Ohio
I'm fairly inexperienced in both C and C++, but I've been learning under Linux/GCC. Let me start out by saying that programming under Linux is great. Why? Because it works. It just does, any time, every time. I don't have to jump threw hoops are do anything stupid for no reason.

I tried programming in Windows and I cant even get simple things to work.

I gave VisualStudio C++ 2008 a go. What a joke. C'mon, is it MFC, is it managed code, is it CLR, is it Win32, you never know what it is your working with. I just want the darn thing to take my code and convert it into a darn binary without millions of unnecessary dependencies.

I cant even get:

Code:
#include <stdio.h>

int main()
{
	char* test[256];
	printf("This is a test!");
	gets(test);
	return 0;
}

to compile without errors. I take that back. It compiles, but it brings up debugging errors when ran.

Then I tried Dev-C++. What a laugh. The above code compiles just like you would expect it to, but try to go any farther than that and your stuck. Tried to do some DirectSound code, and you pretty much have to know all manners of voodoo in order to make Dev-C++ work with ANYTHING.

It seriously seems like The C/C++ languages are not meant for this operating system. It's making me want to stay clear away from it. In fact I've had infinitely better luck programming Win32 in asm using MASM than I have with and C compilers.

You have one anti-social compiler who doesn't like to work with anyone (Dev-C++) then you have the rebel that likes to do everything different for absolutely no reason (VStudio).

I just cant stand things that are needlessly complicated. Several compilers that all operate differently and none of which seem to work when I need them.

:bang head:bang head:bang head

This was more of a rant, but if anyone here has any words of encouragement. Am I crazy or is there some truth behind my experiences?
 
I don't agree with the majority of what you said.

It doesn't matter what the IDE is, or what environment its on, its something you'll have to learn. Just because it doesn't work the first time doesn't mean you can write it off or stay clear from it. You are most likely at fault if it doesn't work. As any programming professional you should be well versed in programming in the Windows Environment and the Unix environment.

If you just code for fun then, okay. If it doesn't work, you can say screw it.

Its quite easy to run C code in Visual Studio.net

Now i'll look at your code...


Your above code is wrong.

Visual Studio gives the following error which shows you where you made your mistake.
error C2664: 'gets' : cannot convert parameter 1 from 'char *[256]' to 'char *'


I then compiled it on a unix system and got the following message:
line 7: warning: argument #1 is incompatible with prototype:
prototype: pointer to char : "/usr/include/iso/stdio_iso.h", line 233
argument : pointer to pointer to char

Warnings are sometimes just as bad as errors, if not worse because they will let you run this program and it isn't doing anything you think its doing.

VC++ is just more strict, its saying, hey, you realize what your doing is wrong, I'm not going to let you go through with this, while the compiler on unix is saying, well yah your probably wrong, but you can ignore this warning and have fun with the output.

If you change the code to the following:

Code:
#include <stdio.h>

int main()
{
	char test[256];
	printf("This is a test!");
	gets(test);
	return 0;
}

BOTH compilers on windows and unix, are fine with it.


If you look at the function prototype of gets you can clearly see that your passing in the wrong argument:
Code:
char *gets(char *s);


So the Visual studio isn't to blame, nor is the operating system. Next time look more clearly at the warnings the unix system is giving you and take note, that warnings should be fixed.



Because I'm bored I'll go further and show you probably what you were trying to do, read from the standard input and then print the array that stores the input.

Here is an example of the program on a Unix system being compiled and run:
tamaria 31% cc -o lol lol.c
tamaria 32% lol
This is a test!
Hi C is so fun
This is what is in the test array: Hi C is so fun
tamaria 33%


Here is the corrected code:
tamaria 33% cat lol.c


Code:
#include <stdio.h>

int main()
{
  char test[256];
  printf("This is a test!\n");
  gets(test);
  
  printf("This is what is in the test array: %s\n" , test);
  return 0;
}


To end my rant, things aren't overly complicated, they are put there for a reason, to keep programmers from making mistakes. That's why I love java so much, it wont let you get away with jack. You do something evenly slightly questioning...it will tell you to f off and try again. Sorry if I sound some what rude to you but you hit a sweet spot in my programming heart. :p
 
Last edited:
Ok, so as it turns out, I saw my mistake shortly after posting. It doesn't help that it was late at night and I was tired.

I retract most of what I said about VC++, now that I've spent some time with it, it's not too bad.

I still think that Dev-C++ is a nightmare when you're working with anything but the main library. Support is minimal, hacks are sometimes required, as are headaches. But in the end I guess you get what you pay for, and if you want, you can ask for a full refund.

Don't worry, you weren't rude. I'm not a big fan of java, but when it comes to managed code I did enjoy the time I spent programming in C#, which is fairly similar to Java. I still prefer native code for most things. but for simple apps that aren't necessarily super performance critical, C# made things really easy and fast.
 
Last edited:
Dev-CPP is where I started really programming.. oh god, memories.. they burn.....
Yeah, that was a dirty hack, the debugger was omgwtfbbq.... autocomplete never worked properly, crash and burn...
Visual C++ 2008/2005 was a huuuuge step up, It was amazing, autocomplete, right click on file "open this file" in code, and debug works as promised....

But honestly both work if you know what you are doing... most of the time.

And in your code
Code:
char* test[256];
Is the error the moment I saw it. gets takes in an array or a single pointer, NOT a pointer to an array. So, let's think.
You have an array
Let's say it starts from memory location 0100. (let's assume malloced instead of stack based...basically same idea)
Your array which you declared.
0100 0101 0102.... 0355 or so.
That's where you CAN write into.
So now you make a pointer to it. Let's say the pointer is put int a location 0001, and it contains 0100.
So, 0001 contains 0100.
Your program tries to write to a 0001, 0002, 0003, 0004, as it believes that's where you got it to be.
Instead, *(0001) would get you 0100 so your program would write good.
And C is by far the fastest there is :).
I compared it to java with heavy computational (to compute perfect numbers for school) and it was faster by about 40% in the first hour.
 
Actually, it's an array of (char*), also known as an array of cstrings.
test[0] is of type char*
test[1] is of type char*
 
I still think that Dev-C++ is a nightmare when you're working with anything but the main library. Support is minimal, hacks are sometimes required, as are headaches. But in the end I guess you get what you pay for, and if you want, you can ask for a full refund.

Speaking of getting what you pay for... Microsoft offers Visual Studio 2008 Professional (or any of a bunch of other titles) free for college students, and they don't seem to have any requirements other than you being enrolled in college.

https://downloads.channel8.msdn.com/Default.aspx
 
Back