Zeige Ergebnis 8.701 bis 8.730 von 10174
C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; woa, woa man WALL of text...
-
06-19-2008, 10:14 AM #8701QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
woa, woa man WALL of text
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
06-19-2008, 11:16 AM #8702Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0

Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
-
06-19-2008, 12:45 PM #8703
- Registriert seit
- Apr 2008
- Beiträge
- 47
- Points
- 2.658
- Level
- 31
- Downloads
- 0
- Uploads
- 0
Hmm... I guess I could just malloc for the netplayers in such a way that if it fails it can run the cleanup stuff and free idle players. I'll play around with it.
Thanks again.
-
06-21-2008, 03:02 AM #8704Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Ummh...... I was wondering, is there an pre-compiled cygwin release, by this i mean like all the files like libmad,
Or should i download the packages from the internet, then
Then would i run an installer that it made, if it makes one (sorry i dont know cygwin very well yet or C for that matter)?Code:cd C:/cygwin make make install
Would i work?
-
06-21-2008, 03:14 AM #8705words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
There is a script on the SVN (in the psptoolchain folder i believe) that will automatically download and install all the commonly used libraries, if not a large majority of them (libmad, libmikmod, pspgl, etc.).
I forgot the script name ,but take a look in the psptoolchain folder or google.
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
06-21-2008, 03:45 AM #8706Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
ok, thanks

Last question: What are the 5 most common libraries, and what to they do?
-
06-21-2008, 04:13 AM #8707Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
The script is psplibraries.
I wouldn't worry about 3rd party libraries yet. When you need them, you'll know how to get them.
Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
-
06-22-2008, 04:33 PM #8708No longer a community member.
- Registriert seit
- Dec 2005
- Beiträge
- 22
- Points
- 46.662
- Level
- 100
- Downloads
- 0
- Uploads
- 0
SDL is confusing me again. Basically, I just want to make a simple image class. This class will load an image in the constructor, and draw it to the screen with x and y coordinates when asked. This should be pretty straightforward.
I have most of the code working. I can load images and free them. However, the problem comes when I try to put the images into a vector. Currently, the code I have gives a Segmentation Fault. And yes, the images do exist. I think this is because I don't have a copy constructor. I have tried to make a few, but I don't think that I am doing this right. Could somebody shed some light on my problem?
The code is below. Yes, I know, it is basic (just the Image class and a main loop). I'm just trying to get this working. Oh, and sorry about the indenting. It looks fine in gedit or code::blocks, but for some reason the forums think that organization is overrated.
Spoiler for Code:
EDIT: I love how as soon as I post, a proper answer is revealed. Looking in the SDL docs, here's how to copy surfaces:
I just wasn't doing the refcount++ part. Therefore, if anybody is wondering, the copy constructor (in my case) is as follows:Code:SDL_Surface *Srfc1, *Srfc2; Srfc1= IMG_Load("foo.png"); Srfc2= Srfc1; Srfc2->refcount++; .. SDL_FreeSurface(Srfc1); SDL_FreeSurface(Srfc2);
Code:Image::Image(const Image &oldImage) { m_pImage = oldImage.m_pImage; m_pImage->refcount++; }Geändert von Hardrive (06-22-2008 um 04:40 PM Uhr) Grund: Posted too soon
-
06-23-2008, 04:01 AM #8709QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You probably would want to implement the assignment operator as well.
An alternative solution is to use a vector of pointer to images:
And new/delete as you push and pop.Code:std::vector<Image*> imagelist;
Or even better, use smart pointers:
http://www.boost.org/doc/libs/1_35_0...shared_ptr.htm
And the Images are destroyed when they are removed from the vector (unless you are holding another reference somewhere else).Code:std::vector< boost::shared_ptr<Image> > imagelist; imagelist.push_back(new Image("number1.png"));[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
06-23-2008, 04:42 AM #8710No longer a community member.
- Registriert seit
- Dec 2005
- Beiträge
- 22
- Points
- 46.662
- Level
- 100
- Downloads
- 0
- Uploads
- 0
-
06-23-2008, 03:07 PM #8711QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
06-25-2008, 08:14 AM #8712
- Registriert seit
- Apr 2008
- Beiträge
- 47
- Points
- 2.658
- Level
- 31
- Downloads
- 0
- Uploads
- 0
Okay, I've been busy. Three quick questions. I'll try to be brief.
1) Is there anything in the standard library that supports regular expressions, or else a popular lib for doing so? sscanf isn't cutting it. (I can try to use the Ruby API if no.)
2) I've been using read() to get data from my sockets, but it seems to leave a '\n' on the buffer when I use it, so I'm being forced to do an additional read() of single char width every time. Is this normal? I suspect I should be using recv(), but I don't know which flags to feed it.
3) From what I understand variables declared in a function are deallocated when the function terminates (unless returned). Is this also true of memory allocated by pointers? IOW, if I declare 'char my_str[32]' in a function do both the pointer and the chars get deallocated when the function ends?
Thanks for any advice. Sorry to ask so many questions.
-
06-25-2008, 09:28 AM #8713QJ Gamer Bronze

- Registriert seit
- Sep 2006
- Ort
- france
- Beiträge
- 170
- Points
- 6.359
- Level
- 52
- Downloads
- 0
- Uploads
- 0
-
06-25-2008, 09:49 AM #8714QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Boost Regex does: http://www.boost.org/doc/libs/1_35_0...tml/index.html
I haven't used it before so I can't advise how to get it running.[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
06-25-2008, 10:03 AM #8715
- Registriert seit
- Apr 2008
- Beiträge
- 47
- Points
- 2.658
- Level
- 31
- Downloads
- 0
- Uploads
- 0
If I say 'char my_str[32];' and then refer to my_str it acts as a pointer, no? Functions that accept 'char *' as args will accept 'my_str'. You're saying that if I have a function that has that line in it I should say 'delete[] my_str;' in order to deallocate the chars themselves?
Yaustar, thanks. I'll take a look.
---------------------------------------------------------
Found a reference. Both the pointer and the array are deallocated (actually, removed from the stack) when they lose scope. You only have to use 'delete' if you created something with 'new'.
Still curious about my socket behavior, though.Geändert von Khatharr (06-25-2008 um 11:44 AM Uhr)
-
06-25-2008, 02:45 PM #8716
-
06-25-2008, 03:12 PM #8717QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
No. It can be degraded to a char * but to the compiler, it is different.If I say 'char my_str[32];' and then refer to my_str it acts as a pointer, no?
Try this code:
Take a look at the the values of sizeOfBuffer1 and sizeOfBuffer2. Conceptually, the difference between a char * and char buffer is important.Code:char buffer1[128] = "Hello World"; char * buffer2 = "Hello World"; int sizeOfBuffer1 = sizeof(buffer1); int sizeOfBuffer2 = sizeof(buffer2);
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
06-26-2008, 10:37 AM #8718
- Registriert seit
- Apr 2008
- Beiträge
- 47
- Points
- 2.658
- Level
- 31
- Downloads
- 0
- Uploads
- 0
I understand what you're saying, I'm just not expressing myself correctly. I view the line:
char mystr[3];
as allocating 3 chars and also allocating a pointer, such that mystr is sort of a 'pointer/char/char/char' which holds both the pointer to the array and the information about the array. I was concerned that perhaps the pointer part would be discarded but the array part wouldn't be, but I found some documentation that explains the handling and it's all good. I was just concerned because I was looking at some example code and the person who wrote it was using malloc in a private function and then freeing the data at the end of the function with no use of realloc/calloc or anything. I didn't/don't understand why he did that. Thanks for the clarification, though.
Am I alone on this socket-reading problem?
-
06-26-2008, 06:41 PM #8719Developer

- Registriert seit
- Aug 2007
- Beiträge
- 74
- Points
- 3.206
- Level
- 35
- Downloads
- 0
- Uploads
- 0
Another important distinction is that buffer1 == &buffer1 whereas buffer2 != &buffer2. An array does not explicitly store an address in memory, that is, there is no value for buffer1 that is stored in memory (buffer1 will take the address of the first element of the array). The pointer on the other hand explicitly stores an address (the address at which will be a variable of type char). So the "Hello World" of buffer1 is stored on the stack, however the "Hello World" of buffer2 is NOT stored on the stack (just the address of the "Hello World" string).
This is an important point to remember.
No it doesnt. It doesnt hold a pointer to the array, mystr really is just 'char/char/char'. The 'pointer' you speak of is just the address of the start of the array, no where in memory will you find this address explicitly stored.PSP PRX LibDoc's Lives On!
http://silverspring.lan.st/
My new home:
http://my.malloc.us/silverspring/
-
06-26-2008, 08:13 PM #8720
- Registriert seit
- Apr 2008
- Beiträge
- 47
- Points
- 2.658
- Level
- 31
- Downloads
- 0
- Uploads
- 0
If that's the case then why doesn't mystr refer to the first char? Are arrays just handled as a distinct type from their non-array equivalents?
-
06-26-2008, 09:10 PM #8721Developer

- Registriert seit
- Aug 2007
- Beiträge
- 74
- Points
- 3.206
- Level
- 35
- Downloads
- 0
- Uploads
- 0
Geändert von SilverSpring (06-26-2008 um 09:22 PM Uhr)
PSP PRX LibDoc's Lives On!
http://silverspring.lan.st/
My new home:
http://my.malloc.us/silverspring/
-
06-27-2008, 12:18 PM #8722
- Registriert seit
- Apr 2008
- Beiträge
- 47
- Points
- 2.658
- Level
- 31
- Downloads
- 0
- Uploads
- 0
Okay, this is too much conversation about something I already know how to use. Thank you all for the clarifications. Does anybody have even the most remove notion about my problem using read() on sockets?
-
06-27-2008, 12:51 PM #8723QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
For clarification, are you using this read function?
http://www.cppreference.com/cppio/read.html
Edit: Nevermind. Does this site help? http://www.pcs.cnu.edu/~dgame/socket...+/sockets.html[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
06-27-2008, 02:07 PM #8724
- Registriert seit
- Apr 2008
- Beiträge
- 47
- Points
- 2.658
- Level
- 31
- Downloads
- 0
- Uploads
- 0
I found some info about the recv() flags and I'll test with recv() to see if it's having the same problem when I get home. Thank you for the link, but I'm only working in C, not C++ yet. I do already have a lot of experience working with sockets in Ruby and Lua and I can easily create, bind, connect and read/write to them. I just can't figure out where these random '\n' are coming from, so I'm trying to figure out if it's normal or if my PSP or perhaps my toolchain install are somehow tarded. If I have the same problem with recv() as I'm having with read() then I'll just have to set my socket reads up to discard any read that starts with '\n' maybe. Since there's no '\0' after the '\n' I'm ending up with things like this:
server sends: "This is a string.\n\0"
PSP reads: "This is a string.\n\0"
PSP reads again: "\nhis is a string.\n\0"
The server's using Ruby's 'puts()', but I had the same problem with data from an incoming telnet socket. Like I mentioned earlier I'd just discard every other read, but about 1 in 100 times it doesn't do it, so I'd be risking data loss.
Acketh... Sorry to WoT again.
----------------------------------------------------
Edit: I guess the quickest way to find out if something's up would be to ask someone to compile and run the tester source I got from BigBlack's post here. If telnetting in and typing results in double characters on the PSP (ie "test" => "tteesstt") then this isn't a unique problem to my system.Geändert von Khatharr (06-27-2008 um 02:31 PM Uhr)
-
06-27-2008, 02:24 PM #8725QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Have you tried making a simple PC client to check what you are receiving from the server? What you are actually sending may not match up with what you think you are sending.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
06-27-2008, 03:53 PM #8726
- Registriert seit
- Apr 2008
- Beiträge
- 47
- Points
- 2.658
- Level
- 31
- Downloads
- 0
- Uploads
- 0
This particular server is well known to me as it's the server that I started to learn socket manipulation with several years ago. It's only about 20 lines long and sends one of three strings, each of them being enclosed in html-like tags, such as "<chat>actual-data</chat>" and they are sent using Socket.puts(), which appends a '\n' to the end of the string. AFAIK Ruby always silently null-terminates its strings. I've never experienced any similar problem with this server in the past, though it is somewhat archaic in other ways.
However, just for the sake of thoroughness, I'll write a simple console app for my PC to test data from the server and see if it experiences the same problem. I don't suspect that this is the case because I'm getting the same strange behavior when I use telnet to connect to the PSP as a server. I'm about to go home for the day, so I'll test using recv() and if that doesn't get it then I'll whip out a quick PC console app to see just exactly what bytes are being sent.
Thank you for your patience and support.
----------------------------------------------
Update:
Wow, hurray for yaustar and for thoroughness. The server is indeed sending "string\0\n", which I don't recall it doing in the past. I did, however, recently upgrade my Ruby install, so maybe it's a bug in the new version, or maybe for some bizzare reason I never caught it in over 3 years of working with this server. I also figured out the reason that it occasionally didn't occur. Seems that if more than one message is waiting on the stream then it would deliver the next message on the next read with the \n prepended to it, so I didn't catch it as a single character length '\n'. Now that I understand this behavioral oddity, though, I've easily coded around it and I'm catching all my data correctly now. Thanks, yau. About the telnet thing, I can't figure out why I thought telnet was doing that. When I tested it last night it worked fine. Maybe I was looking at the telnet screen where the echoes were added to the local characters and I thought it was screwing up. I suppose I should take this as a sign that coding should end at midnight rather than at 6 AM so I can see what the hell I'm doing.
Thanks again to everyone.Geändert von Khatharr (06-28-2008 um 11:05 AM Uhr)
-
06-28-2008, 08:17 PM #8727QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Quick question, how can i remove digits from a float. For example if i have:
how can i cut it down to justCode:float myFloat = 1.234;
? ThanksCode:1.2
-
06-28-2008, 08:27 PM #8728It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
roundf(theFloat*10.0f)/10.0f
:/pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
06-28-2008, 08:34 PM #8729QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
thanks man
-
06-30-2008, 01:34 AM #8730
hello, i am having problems getting the cygwin thing set up. i type in "make" in the shell and it says "nothing can be done for all."


LinkBack URL
About LinkBacks
Mit Zitat antworten



Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum