• Lucid Dreaming - Dream Views




    Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast
    Results 26 to 50 of 102
    Like Tree3Likes

    Thread: Ask me about C / C++

    1. #26
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      That's because your syntax isn't quite right. Try this:

      Code:
      obj_files/AP_commons.o: AP_commons.cpp
         g++ AP_commons.cpp -g -O2 -Wall -MT obj_files/AP_commons.o -MD -MP -MF
      "./obj_files/AP_commons.Tpo" -c
      You can't specify where to compile to in the compile line itself, instead you tell it what output file the compile line belongs to.

      The syntax for compiling only goes:
      Code:
      Target: All dependancies (including libraries)
         compiler command

    2. #27
      Member
      Join Date
      May 2009
      Posts
      139
      Likes
      1
      Quote Originally Posted by ninja9578 View Post
      That's because your syntax isn't quite right. Try this:

      Code:
      obj_files/AP_commons.o: AP_commons.cpp
         g++ AP_commons.cpp -g -O2 -Wall -MT obj_files/AP_commons.o -MD -MP -MF
      "./obj_files/AP_commons.Tpo" -c
      You can't specify where to compile to in the compile line itself, instead you tell it what output file the compile line belongs to.

      The syntax for compiling only goes:
      Code:
      Target: All dependancies (including libraries)
         compiler command
      That one didn't work either g++ thought the *.0 and *.Tp0 were the input files and said it couldn't find them.

      I noticed that I couldn't find any place where it actually used the *.Tpo files, so I experimented this morning with a very simple command line of
      g++ AP_commons.cpp -c
      then moving the *.o files to obj_files manually. That cured most of the problems.

      But then I discovered that g++ couldn't find lroundf in the math library, even though it's there just as much as the other math functions the code uses. Fortunately it was simple to replace lroundf with the expression of (int)(n+0.5)

      After that, g++ couldn't find the system getopt.h, even though it's just as much there as any of the other system inlcudes. So I had to specify the absolute file location in the source code.

      But now, the g++ linking stage can't find getopt_long in getopt.h, even though it is there. And I have no idea how to fix that

    3. #28
      Member
      Join Date
      May 2009
      Posts
      139
      Likes
      1
      Ninja,
      since that package refused to compile, and unfortunately your advice didn't work, I spent yesterday afternoon coding a m4a tag dumping program from scratch in VB. It doesn't allow tag editting or anything, but it runs and serves the purpose I needed it for. So that's all taken care of. Maybe I'll even rewrite it in (working) C code when I have more energy, doing that should at least speed it up and allow me to port it into linux too.

    4. #29
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      Yep, C code runs circles around VB code.

    5. #30
      Explorer of the Mind SuperSmashcz's Avatar
      Join Date
      Jul 2008
      Gender
      Location
      MD
      Posts
      51
      Likes
      0
      Okay so I've started writing my own 3D engine in C++.. it's got a terrain engine and lighting.. ect. How do I take all my classes and turn it into a library? So like i could be like DDHI_MakeTerrain(..) rather than being like including the classes and calling MakeTerrain(..) Basically.. i could wrap up all my classes and import them all using a single .lib and use it throughout other programs i write using those classes?
      From every time we meet, to every time we part, i will add another memory to my shattered heart, and for every dream we chase, another memory will take its place, so we can remember it one day.

      LD's 15
      DILDs 14
      WILDS 1

    6. #31
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      It depends on your platform and compiler.

      First thing that you need to do is declare all of the methods that you want to use as static stdcall. You can't use classes directly, you need to write an interface. something like this:

      Code:
      //This is the interface header, compiled with both your library and your program
      #include "yourclass.h"
      
      static __stdcall void * New(void){
         return (void*)new yourclass();
      }
      
      static __stdcall SomeMethod(void * handle, int other_params...){
         if (handle){
            yourclass * pthis = (yourclass *)handle;
            pthis -> SomeMethod(other_params...);
         }
      }
      Then you need to set up your IDE to spit out a dll instead of an exe. It depends on your IDE on how to do that, if you're using a makefile, then you have to figure it out yourself, I don't deal with makefiles anymore

      You may or may not need to create and define a DEF file, all that does is tells the compiler what the names of the exported methods are.

      Most compilers will spit out both a dynamic and a static library, dynamic ones are probably better because you can change your engine on the fly. That's how games that use both OpenGL and DirectX do it.
      Last edited by ninja9578; 07-11-2009 at 12:17 AM.

    7. #32
      Same great taste! Achievements:
      1 year registered 1000 Hall Points Veteran First Class
      Flavour of Night's Avatar
      Join Date
      Jan 2006
      LD Count
      Thousands.
      Gender
      Location
      East Tennessee
      Posts
      308
      Likes
      0
      Quote Originally Posted by ninja9578 View Post
      Yep, C code runs circles around VB code.
      Damned straight. Once compiled, does VB still toss in enormous wodges of non-essential crap from over-stuffed libraries?

    8. #33
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      Not really, it's fairly compressed. There is some overhead, for instance, strings have about 4 levels of abstraction around then so every string manipulation requires about 4 times the work as in C++. VB is designed to be a learning tool, not a professional programming app, so the compiler is not very efficient at optimizing.

    9. #34
      Member Keresztanya's Avatar
      Join Date
      Mar 2008
      Gender
      Posts
      1,083
      Likes
      32
      What is the best book on C to read?

    10. #35
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      "The C Programming Language"

    11. #36
      Same great taste! Achievements:
      1 year registered 1000 Hall Points Veteran First Class
      Flavour of Night's Avatar
      Join Date
      Jan 2006
      LD Count
      Thousands.
      Gender
      Location
      East Tennessee
      Posts
      308
      Likes
      0
      Quote Originally Posted by ninja9578 View Post
      Not really, it's fairly compressed. There is some overhead, for instance, strings have about 4 levels of abstraction around then so every string manipulation requires about 4 times the work as in C++. VB is designed to be a learning tool, not a professional programming app, so the compiler is not very efficient at optimizing.
      I can still remember compiling "Hello World" for lulz in the old QB 4.5.. 14 Kb for: print "Hello World!"

      C compiled it much tighter only needing the include for stdio.h for the printf.

      Doing it in my old Borland Assembler only took a handful of bytes once compiled and linked to knock out a .com file with a label of:

      mssg db 'Hello World!",13,10,'$'

      then nothing more than:

      lea dx, mssg
      mov ah, 4ch
      Int 21


      Those DOS calls sure are handy. You could do it also with Int 9, but that's a bit more work.

      After awhile, you'd start to recognize the actual machine code for some of the calls and the like.

      Seems silly now, but, I can lay claim to having once owned a 10 meg HD, so the "who cares" attitude of today was a luxury unaffordable back then.

      code is fun, I've not bothered with it in years.. kinda makes me want to get my fingers back in shape.

      .

    12. #37
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      Good for you. I grew up with some less than optimal machines and I got really good at doing optimizations, I still do it. Qbasic was fun

      Code:
      ? "QBasic is awesome!"

    13. #38
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      How do you find the execution time and memory imprint of your code?
      (I'm using windows, btw)
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    14. #39
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      Your memory imprint should be visible in your Task Manager (ctrl+alt+del)

      As for execution time, all you need to do it have your program record the time when it starts, then record it again when it quits. Subtract the two and print the result

    15. #40
      I am God Kastro187420's Avatar
      Join Date
      Mar 2005
      Gender
      Location
      Here is everywhere you are
      Posts
      481
      Likes
      13
      I've always been interested in learning C/C++, but could never find any good reference/learning sources.

      Having an understanding of php and some sql (basic sql functions such as update/insert/delete/drop, enough to maintain a database), aswell as basic Javascript, how hard do you figure it would be to move into the C languages?

    16. #41
      Member Grunkie7's Avatar
      Join Date
      Jul 2007
      Posts
      196
      Likes
      3
      This question is more programming in general but still applies to C.

      I've got a shelf chocked-full of programming books from my brother collected during his college years. Java, C, C++, Python, etc.. Thing is, "Horton's Beginning Java" for example, is a massive book, but it's from 1997. Same with most of the other books (give or take a few years). Have things in the programming world changed enough in the past 12 years to make these books obsolete/incompatible or have they remained fundamentally the same?
      The book cover on my example states 'covers JDK 1.1'

      I have a feeling I aughta move into something more universal; Most of my programming experience is in learning Actionscript out of a 'game programming for dummies' book.

    17. #42
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      The only major change in programming fundamentals is the emphasis on cross-platform programming. The skyrocketting sales of Macs made companies rethink how they designed software since more and more companies were demanding Mac-friendly apps. Because OSX is UNIX based, a side-effect of that was a surge in Linux programming.

      C99 made some big changes. For instance, optional parameters are not preferred over method overloading. You are guaranteed a few more things, and the use of reference counting has increased. That is unless you are using Visual C++. Visual C++ does not adhere to the C++ standards, which is why so few people use it.

    18. #43
      Member
      Join Date
      Jun 2008
      Gender
      Posts
      185
      Likes
      0
      where can I find a good free C++ compiler that I don't need to register?
      If you decide that something is beautiful
      then something else immediately becomes ugly
      without you realizing it
      -Lao Tzu
      Seemingly the bough is the cause of the fruit,
      But really the bough exists because of the fruit.
      -Rumi

    19. #44
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      Most C++ compilers are free, ones that you have to pay for are a scam. The standard is GNU, which is 100% free.

      If you download XCode, the gnu compiler will come with it.
      If you're Linux, gnu c++ is preinstalled on your machine
      For Windows download Code::Blocks, the compiler comes with it.

    20. #45
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      If you're on windows and don't want an IDE, just a compiler, then you can download mingw. I'm guessing that's the compiler Code::Blocks use.
      Microsoft also provide a free compiler, Visual Studio Express, which I think you can get without registering (it includes an IDE)

      Also, ninja, I have a question: If you're dabbling in programming and have learned some C++, do you think it would be a good idea to read up a bit on C too? Would it be useful?
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    21. #46
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      Yes, C++ is a superset of C, so knowing C will be good for C++.

    22. #47
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      Quote Originally Posted by ninja9578 View Post
      Yes, C++ is a superset of C, so knowing C will be good for C++.
      I know that C is still used a lot in embed devices, and I think it's pretty much used to write drivers too. Does C have any other major uses?
      Cause for regular application development, I think other languages like C++ have the edge.
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    23. #48
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      It depends on what the application is. Huge applications use C++ because it's easier to write object oriented programming. C has a major advantage of speed though. Games and graphics programs are largely written in C and will be until the C++ optimizers can rival human C code in speed and efficiency.

      Lots of programs are written in multiple languages and are heavily modularized. I've written a few programs in both C++ and C. C++ tends to be my framework, however I pull large chunks of it out and put them into dlls which I usually write in C.

    24. #49
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      The other day I started wondering how scripting language interpretors are implemented. As I recall you've written quite a few of them. Do you think you could give me the general idea?
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    25. #50
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929
      Well, they're surprisingly simple. They are two parts, a parser, and a runner. The parser converts them into a vector (I use a vector, could be any container) of strings. Then have a compiler which converts them into more optimized code using callbacks and such. So:
      Code:
      @If(@Add(1, 2) = 3, 
         ++%i%;
         ++%j%;
      else
         --%i%;
      )
      Would get converted into five string vectors that would end up like this.
      Code:
      ID | Function | parameters                  | nextfunction
      1:   @Add,      1, 2                          <back>
      2:   @PreInc,   i                             <3>
      3:   @PreInc,   j                             <back>
      4:   @PostInc,  i                             <back>
      5:   @If,       <1>, =, 3, <2>, <4>           <end>
      Then run that set of vectors through a compiler which converts the command into a callback to a function and creates a class containing all of that information. You also need a runner class which knows that <5> is actually the first one to be run.

      Then when you run the thing, you start on <5>, calling the callback associated with it, and it analyzes each parameter, if it encounters a <#> it runs that command too. Then after if does the first command (<5>) fully, it uses the next member to figure out which function goes next, if it's <back> or <end>, then it stops what it's doing and returns.


      Weird, huh?

    Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast

    Bookmarks

    Posting Permissions

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