Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » existential crisis about C./C++ and makefiles

This thread is locked; no one can reply to it. rss feed Print
 1   2 
existential crisis about C./C++ and makefiles
Neil Roy
Member #2,229
April 2002
avatar

http://support.microsoft.com/kb/830473 said:

On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that you can use at the command prompt is 2047 characters.

Never had a problem with it myself.

---
“I love you too.” - last words of Wanda Roy

Arthur Kalliokoski
Second in Command
February 2005
avatar

I remember trying to do a "dir /s > /dir.txt" and having all kinds of PATH TOO LONG errors scroll by with truncated lines in the text file, just because MS likes to bury stuff nine directories deep.

They all watch too much MSNBC... they get ideas.

Neil Roy
Member #2,229
April 2002
avatar

I just tried that command out (took a while!) and had no problems at all. But that is what you would download CoreUtils for, so you could use ls instead. But it did work for me.

Total Files Listed:
89247 File(s) 99,000,874,321 bytes
24296 Dir(s)  304,396,386,304 bytes free

And that was just from my user folder, glad I didn't do it from root. ;)

---
“I love you too.” - last words of Wanda Roy

Arthur Kalliokoski
Second in Command
February 2005
avatar

Could you try a "wc -L /dir.txt"? (get length of longest line)

They all watch too much MSNBC... they get ideas.

Neil Roy
Member #2,229
April 2002
avatar

216. I just done it from root so I could be sure to get the longest.

---
“I love you too.” - last words of Wanda Roy

Arthur Kalliokoski
Second in Command
February 2005
avatar

You haven't installed the Direct X SDK, have you? ;D

They all watch too much MSNBC... they get ideas.

Neil Roy
Member #2,229
April 2002
avatar

Not yet, no. ;)

I had it on XP, I should try that on my old XP drive, it's still cluttered with old XP stuff....

[edit]
Okay, just done that on my XP drive, it has DirectX SDK from March 2009 on it and the longest line was 213.

---
“I love you too.” - last words of Wanda Roy

William Labbett
Member #4,486
March 2004
avatar

There is an excellent tutorial for C++ here :
cplusplus.com C++ tutorial

Seems good but I'm reading the bit on Classes II and it introduces this :

Vector&

but I can't find any explanation for it earlier.

Don't worry, I've got a C++ book where it's explained.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

A reference (object&) works like a regular object but allows you to directly modify another object without explicitly using a pointer to it.

void set_to_5(int& i) {
   i = 5;
}

int num = 0;
set_to_5(num);
printf("num is %i\n" , num);// "num is 5"

From the example they gave, they are using a class method to return a reference to the object in use. This is useful because it allows you to chain function calls. Take for example the basic prototype for operator << for ostream :

template <class Type>
ostream& operator<<(ostream& os , const Type& t) {
   os << t;
   return os;
}

ostream os;
os << a << " plus " << b << " is " << a+b << std::endl;
// (os << a) returns a reference to os, so after this call it becomes
// (os << " plus ") and so on...

Neil Roy
Member #2,229
April 2002
avatar

I tried references one time and kept getting compile errors, used them just like you did and I ended up changing them to pointers. Would have been nicer to have the references.

It was just a basic function at the time like

[EDIT] actually it was class I made I was trying to pass.

[Edit2] Nvm, my bad. ;)

---
“I love you too.” - last words of Wanda Roy

Arthur Kalliokoski
Second in Command
February 2005
avatar

You didn't compile as regular C, did you?

They all watch too much MSNBC... they get ideas.

Neil Roy
Member #2,229
April 2002
avatar

It worked when I changed it, considering it uses a class (sorry, just edited as you were replying I think), I definitely compiled it as C++.

[edit]
Hmmm, nvm. I think because it is a class, it's already a pointer and so there is no need for a reference. ;) Was my first time trying to avoid globals and I hadn't use them very much.

---
“I love you too.” - last words of Wanda Roy

bamccaig
Member #7,536
July 2006
avatar

Being a class has zero to do with references in C++. Show us the code and we'll help you understand it. :)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Neil Roy said:

I think because it is a class, it's already a pointer and so there is no need for a reference.

Being a class doesn't make it a pointer. If you want to modify an object directly in a C++ function you have to use a reference or a pointer.

class Ex {
public :
   int x;
   Ex() : x(0) {}
};

void SetTo(Ex& ex , int x) {
   ex.x = x;
}

Ex ex;
SetTo(ex , 5);
if (ex.x == 5) {printf("Yay, references work!\n");}

Neil Roy
Member #2,229
April 2002
avatar

I went back and took a look at my code again and it seems to work better now. The problem is I have an array that I was passing.

void Draw_Everything(Ball &ball, Paddle *paddle)

paddle is an array (paddle[2]), ball is not, so I can use a reference on ball, a pointer on paddle and this way when I call Draw_Everything() I don't need any reference & pointers on either, which is nice.

Been trying to minimize global variables which I have been really bad for in the past. I do like how much more neat and tidy C++ classes seems to be making the code which will help in tracking down bugs I imagine. As I port over old projects, I'll make an attempt at converting to C++ and see how that goes. I have an asteroids "game" (not really a game, just some asteroids floating around) that was an excersize in using linked lists. I looked at it and realized it would convert into a C++ class really easily. There's basically an asteroids struct, with a bunch of functions for handling various things like adding a new asteroid, initializing it, functions for moving it etc...

---
“I love you too.” - last words of Wanda Roy

bamccaig
Member #7,536
July 2006
avatar

There are objects available in C++ to use for arrays instead of raw sequential memory blocks and pointer arithmetic. :) std::vector is sort of like an automatically, dynamically-sized array. boost::array (from the Boost framework) is a statically-sized array wrapped in an object for convenience. You're probably pretty comfortable with C arrays anyway, but you might consider giving these objects a try as alternatives. :)

 1   2 


Go to: