|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v8 <voi### [at] devnull> wrote:
> Yup. A simple and obvious mistake. But unfortunately, not one the
> compiler warned me about.
Than turn on the warning flags. You should always compile with warning
flags.
g++ -Wall -Wextra -pedantic -ansi -O3 yourprogram.cc
Learn to use makefiles too. You can use the attached generic makefile
to automatically build your program. (You'll probably need gnu make.)
(Note that if you add, remove or change any #include line in your
program, except those which include standard libraries, you'll have to
delete the .dep file before running make.)
Post a reply to this message
Attachments:
Download 'Makefile.txt' (1 KB)
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>> Yup. A simple and obvious mistake. But unfortunately, not one the
>> compiler warned me about.
>
> Than turn on the warning flags. You should always compile with warning
> flags.
>
> g++ -Wall -Wextra -pedantic -ansi -O3 yourprogram.cc
Actually, when I want to compile something, I usually just say "make
foo". Otherwise GCC insists on naming it "a.out", which is very irritating.
I'm rather surprised that forgetting to return anything at all isn't
considered a non-maskable error, but anyway... (Certainly returning
something from a void function seems to cause an error.)
I guess at some point I'll have to read the GCC manpage to find out how
to control it directly.
> Learn to use makefiles too. You can use the attached generic makefile
> to automatically build your program. (You'll probably need gnu make.)
>
> (Note that if you add, remove or change any #include line in your
> program, except those which include standard libraries, you'll have to
> delete the .dep file before running make.)
So there *is* a way to automate dependency analysis?
Personally, I'm used to a programming language where I write some code,
save it in a couple of files, and say "ghc --make Foo" and it
automatically builds a dependency tree, decides which things do or don't
need recompiling (including noting whether the *external* interface is
different or not), compiles everything to machine code, and
automatically links all the necessary libraries.
This whole concept of having to manually write makefiles and manually
write header files and so forth just seems tedious and error-prone.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Slime wrote:
> What compiler are you using?
GCC, on Linux, running under QEMU. (Because it's what I have to hand.)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>> If it's possible for you to acquire a copy of Visual Studio (even an
>> oldish one), I strongly recommend it.
>>
>
> Related to that, the express editions of Visual Studio are available
> free of charge.
Hmm. OK, maybe I'll give that a try at some point.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> Warp <war### [at] tagpovrayorg> wrote:
>> Another C function can be used to both parse an integer from a string
>> and know if there was one: strtod(). However, its usage is even more
>> complicated than atoi().
>
> Yeah, it's strtol(), not strtod(). The latter is to read a floating
> point number.
>
> (This shows how clear those C function names are... ;) )
<insert "I told you so" remarks here> ;-)
At least C++ manages to be a little more intuitive here.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v8 wrote:
> Besides, Emacs isn't even a text editor - it's an operating system! ;-)
More technically, "Emacs isn't a text editor, it's an EList interpretter
that comes bundled with a text editor implementation". :^)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>> Have *you* ever tried to make Vim or Emacs work? :-P
>
> I have used both for years at a time.
Well forget the comments about M$ Word training courses - surely you
must have taken some pretty advanced courses to be able to comprehend
either of these editors!
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v8 <voi### [at] devnull> wrote:
> Orchid XP v8 wrote:
> > Besides, Emacs isn't even a text editor - it's an operating system! ;-)
> More technically, "Emacs isn't a text editor, it's an EList interpretter
> that comes bundled with a text editor implementation". :^)
I use emacs to write C++, in both Linux and Windows (where I program
for my payjob). Of course it's a heavily configured emacs.
If you ever want to use emacs, I could give you my emacs configuration
file. It sets up quite many things which make it more usable.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v8 <voi### [at] devnull> wrote:
> > g++ -Wall -Wextra -pedantic -ansi -O3 yourprogram.cc
> Actually, when I want to compile something, I usually just say "make
> foo". Otherwise GCC insists on naming it "a.out", which is very irritating.
If you don't specify an executable name, how can gcc guess what is it
that you want? Note that you can write something like:
g++ file1.cc file2.cc file3.cc
Which one of those is the one you want the executable named after?
Or maybe you don't want the executable to be named anything those.
AFAIK all compilers require you to specify an executable name. It's
just that in most compilers this happens when you are creating a project.
However, gcc is command-line oriented and doesn't have projects. It doesn't
need to support projects because 'make' is the de-facto project software
in unix systems, and there's no need for gcc to step onto its toes.
Of course the way to tell gcc the name of the executable is to tell it
to it with the -o parameter.
> I'm rather surprised that forgetting to return anything at all isn't
> considered a non-maskable error, but anyway...
C++ inherits many things from C, good and bad.
> > Learn to use makefiles too. You can use the attached generic makefile
> > to automatically build your program. (You'll probably need gnu make.)
> >
> > (Note that if you add, remove or change any #include line in your
> > program, except those which include standard libraries, you'll have to
> > delete the .dep file before running make.)
> So there *is* a way to automate dependency analysis?
The -MM option of gcc (which I use in that generic makefile I attached)
auto-generates makefile dependencies for all the specified source
files. Makefiles themselves (at least with gnu make) are so versatile
that this can be used to completely automatize dependency building.
Well, *almost* completely. 'make' has no way of knowing if you have
changed some #include line in some source code file, which would change
the dependencies. Of course it would be perfectly possible to make it
build the dependency file every time you run 'make', but I usually don't
want that, because the "g++ -MM" command often takes a few seconds to run,
which can be irritating, and dependencies change rarely.
If you want it to run the "g++ -MM" every time, you can do it like in
the attached Makefile.
> This whole concept of having to manually write makefiles and manually
> write header files and so forth just seems tedious and error-prone.
You don't need to manually write makefiles. Just use a generic one.
Post a reply to this message
Attachments:
Download 'Makefile.txt' (1 KB)
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Nicolas Alvarez wrote:
> I understand the C++ one and the Haskell one looks like line noise.
Uh-huh, and let me guess: You already know how to read and write C++
fluently, but you know nothing about Haskell yet? :-P
Seriously, I am constantly baffled by statements like this. The code I
posted contains one line which is a little cryptic (the really long one
where I dump the stack to stdout with 1 line of code). Other than that,
it's all really quite straightfoward.
Or are you seriously telling me that the meaning of
if (cmd == "^") break;
if (cmd == "+") {Add(stack); continue;}
if (cmd == "-") {Sub(stack); continue;}
stack.push_back(1);
is somehow clearer than
case cmd of
"^" -> return ()
"+" -> binary (+) stack
"-" -> binary (-) stack
_ -> main_loop (1:stack)
?
To me, all that tricky slight of hand with "break" and "continue" seems
far less clear then just directly saying exactly what you want to
happen, as the Haskell version does.
I really can't figure out what everybody finds so confusing about
Haskell. Is it just that it uses different syntax to other "common"
programming languages? (E.g., no curly braces, no function call
brackets.) Or is it something deeper?
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |