Planning to write a C++ Pre-Processor tut
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Planning to write a C++ Pre-Processor tut

  1. #1
    Senior Member
    Join Date
    May 2002
    Posts
    344

    Planning to write a C++ Pre-Processor tut

    Hey guys i am planning on writing a C++ Pre-Processor tutorial. Anyways, we will learn how to write macros and how to make header files and how to use them in your programs. Also, this tutorial will cover all of the escape characters (because i think they are important and think they are fun to use ) and how to make comments in C++ (there is a cool way to comment things out in C++ using the pre-processor which ill teach you guys how to use). Anyways, if there is something you guys would like me to cover in the tutorial, let me know and i will try to add it in
    Support your right to arm bears.


    ^^This was the first video game which i played on an old win3.1 box

  2. #2
    Senior Member
    Join Date
    Jan 2003
    Posts
    220
    Wow that sounds awsome....I think thats a great idea! Maybe you could list a few reference links to freeware compliers and tut sites. Good luck!
    [gloworange]And then it happened... a door opened to a world... rushing through the phone line like heroin through an addict\'s veins, an electronic pulse is sent out, a refuge from the day-to-day incompetencies is sought... a board is found. \"This is it... this is where I belong...\" I know everyone here... even if I\'ve never met them, never talked to them, may never hear from them again... I know you all...[/gloworange]

  3. #3
    Senior Member
    Join Date
    May 2002
    Posts
    344
    alright...will do also if you want ill add a list of books that really helped me out when i was first learning C++
    Support your right to arm bears.


    ^^This was the first video game which i played on an old win3.1 box

  4. #4
    Banned
    Join Date
    Aug 2003
    Posts
    130
    Sounds good looking forward to it

  5. #5
    Senior Member
    Join Date
    Sep 2003
    Posts
    500
    /*sounds like a plan*/


    I will enjoy reading it.

    One idea: You could provide some basic Unix commands as well for all the windows people.
    You shall no longer take things at second or third hand,
    nor look through the eyes of the dead...You shall listen to all
    sides and filter them for your self.
    -Walt Whitman-

  6. #6
    Senior Member
    Join Date
    Jan 2002
    Posts
    1,207
    But the preprocessor sucks, macros suck, and there are better ways of doing them in C++. Most compilers do inline functions, you know, which are vastly better than macros.

    Anyway you want to know why C sucks?

    http://www.projectz.org/index.html%3Fid=182.html

  7. #7
    Senior Member
    Join Date
    Sep 2003
    Posts
    126
    sound like fun...but I am sort of mastacistic (or somthing like that ) bring on the tut.
    [Shadow] have you ever noticed work is like a tree full of monkeys you look down and all you see is monkeys below you then you look up and all you see is a bunch of *******s above[/shadow]

  8. #8
    Senior Member
    Join Date
    Dec 2001
    Posts
    134
    Slarty no offense but half of the argument in that link you gave is that people new to the language won't know the syntax.

    Just because it's not in straightforward english so that anyone can read it doesn't mean it's a bad thing, using shorthand can speed up the time it takes to code things because you don't have to spell out long words all the time, and on top of that most of the shorthand used makes reasonable sense on its own.

    The point on the pre-processor is true however, but I've never had to define variables with it, I really don't see the point. If you need to define a variable then use the if built into the pre-processor, define should only be used for setting things that control code alteration like what OS the code is compiled on, etc...

    The assignment syntax is fine, sure the == part can cause grief at first but the concept isn't that hard to wrap your head around, most people I know never considered it a problem when they were learning. As for x = y = 456, the assignment operator works from the far right first and assigns to the left, that simple, there's no tricks to it.

    The ternary "?" operator is very useful for adding conditionals in places where you just need a quick if/else and are only returning variables based on it. One of the handiest places to use this is when formatting text for output, you can put it right in the output statement.

    For loops are no good? Maybe the author should look at their code, because he messed up the while loop that "emulates" a for loop, the i++; should be at the end of the loop so that it increments in the right place. A for loop keeps the incrementing and initialization in a common place making it easier for a newbie to see what the loop is doing, the 0 to whatever is just something that you get used to, many compilers count 0 as the first number, learn it and get over it.

    The fact that anything can be used as boolean is extremely handy, sure without proper naming it gets confusing but otherwise it makes checking things nice and simple.

    I will agree with the strings though, c was awful for strings, c++ is a big improvement in that area, while there are still places where it could be better.

    Pointer arithmetic is fairly straightforward, if you pass the memory location of a character to the character formatter in printf it prints that character, to the string formatter, it prints from that memory location until it finds the null. the memory for a single variable is sequential, it doesn't got 0,3,2,6,1,4,5 it goes 0,1,2,3,4,5,6 so referencing the 3rd character in the variable is a simple task of adding the appropriate number to the pointer, ie memory address, or using the variable as an array which does that for you.

    Multidimensional arrays... I seem to recal using them in c, and c++.. sure they're limited by size constraints which is a pain but that's where vectors come in in c++... Yes I'll admit I like c++ much more than c simply if simply for the stl and streams.

    Typdefinition makes for easier readability in most cases, I really don't see what the authors problem with it is...

    Default scope is global? I seem to recall that if you define a variable in a function it lived and died in that function but never left it. If the author ment that it was global if defined outside any functions in the code then yes.. that would usually be where you declare global variables. And while static isn't the best keyword they could have used it's not all that out of the blue.

    Modules take some getting used to but would you rather read a file that's 3,000,000 lines long or have many little files that you can read over and see what it's doing without getting lost in the code? This makes it easier to read and modify.

    I do agree with the printf being error prone.

    While there is truth to some of what you say, a lot of it isn't all that accurate, you leave out why the "feature" was put there in the first place. C is not by far the best language out there but it's small and easy to write little programs with little code, something Java makes a chore out of, and it's fast.

    As for the pre-processor tutorial, to get back on track, I think it'd be a great idea. But when you write it keep in mind the problem that Slarty pointed out, #DEFINE shouldn't be used to declare variables in most cases and if it is you should put brackets, "()", around the definition to keep the order of operations intact. If you purposely need to have the side effect that Slarty mentioned happened then chances are you don't need that tutorial.
    Reality is the one who has it wrong, not you

  9. #9
    Senior Member
    Join Date
    Sep 2003
    Posts
    554
    Hey Eskimo, this sounds like it's going to be the Tutorial of all Turorials.

    I'm looking forward to it, i have just finished learning html
    and im looking for something else to learn.

    Although i might need to start with the basics, and work my way up to C++
    As i heard you need to learn C first, so would that be correct?

    Anyhow Hello to you all.

    And what a wonderful place this is......

  10. #10
    Senior Member
    Join Date
    May 2002
    Posts
    344
    As i heard you need to learn C first, so would that be correct
    Well creative, there are mixed views about that. I personally never learned C before i learned C++ and i was told that if i did i would develope bad habits...anyways, you could learn it, but you dont HAVE to know any C in order to understand C++.

    DEFINE shouldn't be used to declare variables in most cases and if it is you should put brackets, "()", around the definition to keep the order of operations intact.
    Very true...i will have some examples of what NOT to do and how working with the preprocessor can result in some bad errors. Also, i will explain some usefull things that the preprocessor can help you with.

    But the preprocessor sucks, macros suck, and there are better ways of doing them in C++. Most compilers do inline functions, you know, which are vastly better than macros.
    True indeed slarty--but you have to understand all because something sucks doesnt mean that we shouldnt learn it...There are different ways of doing things in C++ that dont involve the pre-processor and i will mention some of them to you guys in my tutorial. About inline functions, well, sure they could work, but it never hurts to know a little bit about the preprocessor

    Anyways, i currently have written only 2 pages (my tutorials normally tend to be 5-6 pages long), so dont expect this to come out any time soon. I have a history test and a french test this week, so plan on it coming out next week some time...after the weekend so i can wrap stuff up. Anyways, i am looking forward to it
    Support your right to arm bears.


    ^^This was the first video game which i played on an old win3.1 box

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •