• 0

C/C++ compiler headaches


Question

Hi, all!

This question is directed at the more experienced programmers, the veterans, though anybody's advice/ comments are welcome!

Backgroud: Well, I'm up to page 450 or so of Jamsa's C/C++/C# Bible, and still making progress in learning the language. But it's still very rocky! It seems that, (with a total of six C++ books on my desk, endless tutorials and example code on the web, and having Microsoft's Visual C++ beginner's edition, Bloodshed Dev-C++, Borland's compiler, the DJGPP compiler and libraries for all installed on my computer) I would be able to find two example programs in a row that work on the same compiler.

But that's almost never the case. I go to try an assembly routine on Microsoft's compiler. Whoops, the

asm

function has been changed to the

__asm

function! Why? Just to be incompatible? I am itching to do console graphics (just to play, understand!), but NO compiler I have has the graphics.h header file that EVERY book I have talks about. Even the documentation in the compilers themselves go on about

lineto

functions, providing sample code...which errors all over the place (fatal error, file not found)! Well, I finally DID find a console graphics library online, complete with the graphics.h header, and it works on my compilers (Beautifully!)... so WHY were these functions omitted? Just to waste my time for a week to find them?

streql

is unsupported, but after an hour's searching every header file on the hard drive I find

strcoll

, which...does the same thing!

Every other function I want to use is unsupported, or is changed from version to version, or has been moved to a different header file (!?!?) under a slightly different name. Only through groveling through the header files and library extensions for half the day can I find the function that does what I want.

Which is to say that I CAN deal with it. It's just that, somehow, I have the sneaking suspicion that learning to program should have more of a focus on coding happily away, and not spending 90% of the time fighting the system! I mean, how many times can I pick a function described in two or even three books in exactly the same way, only to type it in and get "undeclared identifier", before I start to wonder if I'm really working in the right language?

My general question is, do these headaches ever get less frequent? As an experienced programmer, do you ever reach a "break-even" point where you are able to declare your own function prototype in source, so you're not helpless because you don't have The Magic Header File? Is part of my problem that I'm doing this on Windows 98, which has NO Dos to speak of; would Unix or a pure Dos system be easier? And if so, where can I get a version of Unix to throw on one of my other comps? It would be nice to use that Emacs editor of which I hear so well of, and which I have a copy of, but it even requires a special key on the keyboard which I don't have with a Windows system. Would it do me good to go the Unix/ old Dos route, or would this be yet another wrong tree to bark up? And my Microsoft compiler says it's not ANSI compliant. Is this part of the issue?

Or am I just NUTS? I am doing this on my own free time, out of my own pocket, just because I want to. I may take a class in it eventually, but for right now, I still seem to be getting somewhere on my own! Anybody got some deep Zen wisdom on this note? And if it's this hard for a hobbyist, how on Earth do you cope when you have a classroom/job deadline?

My apologies for the big long ramble, but I know that I'm not the only newbie who's struggling. Just Google "graphics.h C++" and you'll see dozens of people whining in the same pitch that I am, here. Apparently, in finding the console graphics module , I accomplished what hundreds of others have tried to do and failed...

regards and respects,

Hosiah

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Yes, there is a break-even point. Starting out with C++ can be a real headache, because it's not an easy language to master. You exacerbate this by trying to use several different compilers.

There is a large part of C++ that is standard. But there are a lot of things that you want/need to use that are not part of the standard, and every compiler vendor implements them in a different way (for example, Microsoft prefixes these things with a double underscore, Borland does not). Sampling several different compilers before you've become familiar with the language is going to confuse you EVEN more if you try to start using one of the C++ frameworks. So, pick a compiler and stick with it until you're more comfortable.

As frustrating as it may be for you, it's going to get worse. What newbies don't understand about programming is that it's complicated. There's a lot to learn (particularly in a GUI environment), and even once you've learned it all, it will probably be a long, long time before you're any good at all. Like you, I learned to program in my spare time (I've never taken a class or anything). I started learning C in 1994. It took a couple of years before I was able to write a coherent program that was larger than a single module, and another year before I could actually write something that a real person would consider using. By 1998 I was skilled enough to actually make something that was good enough to release into the wild ("good" in that sentence is extremely relative; the program was adequate at what it did, but it was about a million light years from being a good program). In 2001 I was finally able to write a good program, but even by that time, what I released needed several rounds of patching for bug fixes and stability. It's very recent that I have a tremendous amount of confidence in my code, and enough skill to write and release something that's good, usable, stable, and relatively bug-free.

If you're just doing this in your free time, you gotta have patience, because it's going to take you a long time before the learning you're doing now really pays off.

Link to comment
Share on other sites

  • 0

VC++ 6 isn't all that great about being compliant (although there's much in the programming world that still doesn't have standards, which leads to differences in the way they do things such as the asm) if that's what you're using. VC++.net is a little better about it. The reason VC++ is so different is because the way it does asm is pretty weird compared to some compilers. Although gcc (at least for Linux) does some things differently like they use movl instead of mov, which is fine, it's just the start and destination locations are backwards, but it shows that compilers do things very differently.

If you want more compliance, use gcc. You can get it through cygwin or I think Borland C++Builder uses it too, and of course Linux and Unix has it. I'm sure your keyboard has the keys necessary to use emacs. If you mean things like the Meta key, it's just simply alt.

Pure DOS probably wouldn't help you, *nix might. DOS may actually be a bigger headache. You can get Linux distributions off LinuxIso.org.

It's not easy trying to cope with a classroom deadline either, you only get a couple weeks max on a project, so you sometimes have to turn in buggy code and hope for the best. I guess the same goes for real world stuff, you may get a little longer, but I bet there will still be bugs in there (unless it's a really simple program or you get lots of time). This is why when you look at opensource projects, they keep on working until bugs are fixed, even then they sometimes create new bugs. Same behind closed source projects, only you don't get to know about the bugs they squash unless you can understand things like what they put up on Windows Update. Wish I had some deep Zen wisdom to give, but programming will always give you headaches. If you take upper level courses in programming, expect long nights at your keyboard typing away. I may be strange, but I actually enjoy it. Programming is part art, part problem solving.

I feel classes really help on it because you have an expert (at least you hope your professor is an expert or they're just wasting your money) to ask. Plus you get someone looking over your code and giving you feedback. Not to mention you get to work under pressure, so you know if you can handle it or not (since you'll be under pressure if you're doing this in the real world).

Edited by kjordan2001
Link to comment
Share on other sites

  • 0

Oh just wait until you get linker errors. Probably the worst aspect of c/c++ is the way header files work. Well not header files, since that's just a concept, but the way it links everything.

Link to comment
Share on other sites

  • 0
Oh just wait until you get linker errors. Probably the worst aspect of c/c++ is the way header files work. Well not header files, since that's just a concept, but the way it links everything.

Not to mention recursive includes, they can be a pain in the ass.

Link to comment
Share on other sites

  • 0
Not to mention recursive includes, they can be a pain in the ass.

Exactly. That's what I meant. Even #pragma once in MSVC++ can't solve everything.

Double dependency is a bitch too.. or even triple dependecy. Although there IS a way around it, if it's within a project. Across projects gets tricky :(

Link to comment
Share on other sites

  • 0
Exactly. That's what I meant. Even #pragma once in MSVC++ can't solve everything.

Can't solve ANYTHING. As far as I can tell from my own experience, #pragma once doesn't actually DO anything.

Link to comment
Share on other sites

  • 0
Can't solve ANYTHING. As far as I can tell from my own experience, #pragma once doesn't actually DO anything.

#pragma once

Specifies that the file will be included (opened) only once by the compiler in a build. This can reduce build times as the compiler will not open and read the file after the first #include of the module.

For example,

// header.h
#pragma once
....

Link to comment
Share on other sites

  • 0

My Advice on your problems is to stick with ONE compiler. Grapple it as much you you can. When you get at a comfortable level then probably start off with another. The more books you juggle aroud, its going to be frustating for you. Regarding a console grafix library you were expecting something that wasn't supposed to be part of a GUI based Compiler. Borland used to come with a DOS Compiler (Turbo C++, I think it went upto ver. 4.5) that was supposed to have it. And most books on C++ that "claim" to adhere to ANSI forget about a compiler's compliance to ANSI standards, their mistakes cause problems with people trying to learn C++. I hope it helps you understand why you have to face so many problems!

Whether these headaches get less frequent ..... depends. Every compiler suits a particular platform. What you're trying to accomplish & your target platform decide what compiler to use. The key to happy programming (well atleast free of compiler woes) is to realizing what works best for you.

Link to comment
Share on other sites

  • 0
#pragma once

Specifies that the file will be included (opened) only once by the compiler in a build. This can reduce build times as the compiler will not open and read the file after the first #include of the module.

For example,

// header.h
#pragma once
....

Yes, I know what it's SUPPOSED to do. That's a lie. As far as I can tell, it just simply doesn't work. Supposedly (and this is according to Microsoft) it's supposed to prevent the compiler from barking at you about multiply declared objects if you reference the same header file in multiple units. Last time I tried using it, it didn't do anything at all. I followed the docs to the letter, and #pragma once just wouldn't do anything. Same went for the #ifndef solution.

I tried to cajole it into working for hours, following the MS directions for fixing problems with VS; clearing various caches, setting various preferences. No matter what I did, #defining something in one module would not stop the compiler from compiling the code within an #ifndef block checking for the definition, and marking a file with #pragma once didn't stop the compiler from re-reading that file whenever it had a hankering.

I have never before or since been so frustrated I was ready to heave my computer across a room ( :woot: <-Me at the time, laughing crazily). I worked around the problem by packing the "offending" code into a DLL with several functions serving as an interface (call it the pre-.NET .NET solution :) ). It was probably overkill, but after hours and hours of working on this one, STUPID little problem, I didn't care.

</rant>

Anyway, as far as I'm concerned, #pragma once and #ifndef are totally useless (at least in the Microsoft DE). I've yet to see evidence that the compiler even SEES those directives.

Link to comment
Share on other sites

  • 0

Dear fellow collegues,

Thank you, thank you, and THANK YOU!!! for the feedback, advice, and sharing of frustrating experience. OK, at least I know I'm not crazy (at least not clinically so), that this is NORMAL for the experience that I'm having.

Don't get me wrong. I'm not discouraged in the least. And yes, I actually find the whole experience enjoyable, too. I dig the idea that it's half art-form, half problem-solving. As long as I know that I'm not having such a terrible time that it's HOPEless, I'll happily continue!

Peace and Love,

Hosiah

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.