|
GrumpyDoctor posted:What's more conventional when using classes out of the STL: "using namespace std;" in each .cpp file in which it matters, individually importing the symbol for each class you're using ("using std::vector", "using std::list" or whatever), or explicitly qualifying every occurrence of the symbol ("for (std::vector<int>::iterator p...")? Is there even a convention? I feel weird pulling in entire namespaces to save myself typing.
|
# ? Feb 2, 2009 18:22 |
|
|
# ? Apr 19, 2024 05:00 |
|
julyJones posted:I'm not familiar with the type of development you're doing, but when I used VB 6 on a past project, I had to run "regsvr32" to get Windows to register any third-party DLL's I wanted to load. I figured it out, turns out that the dll I was using relied on an older dll for some functionality. I ran it through dependency walker and it let me know what was wrong....I also have to wrap the functions using DllImport, and define the entry point of the dll.
|
# ? Feb 2, 2009 20:17 |
|
I am quite new to C++, so this might be a stupid question for many of you, but I hope I will get some help on this issue anyway. I am trying to pass data between two applications, the first one is based on QT, and the second one on DarkGDK. The QT application will supply data (coordinates mostly) for displaying 3D data in the second application. I have tried googling and asking friends, but no one seems to have a good solution for this. So far, the two options I have considered are: 1. QT opens file, writes to file, closes file. Display opens file, reads, closes. 2. They share(?) a socket, and pass data with this. The first option I would be able to implement myself, but I suspect it will be much too slow for operation in main-loops. The second one, unfortunately, I have no clue how to do. How hard is it to implement a socket system? Would I be able to pass data-structs/classes with it? Will I need to load external libraries or such? Could you please give me some hints, and perhaps point me in the right direction? Thanks guys! Edit: Oh, win32 system, using Visual C++ 2008. Orbitize fucked around with this message at 20:52 on Feb 2, 2009 |
# ? Feb 2, 2009 20:36 |
|
Sockets are one of the easier ways to do IPC. Windows' implementation of them, sometimes called Winsock, is generally compatible with regular Berkely sockets (notable incompatibilities: you need to call closeSocket(sockfd) rather than just close(sockfd), and you need to set up a WSAData structure beforehand; also, you only include winsock.h rather than sys/socket.h netinet/in.h etc). Googling "socket IPC" should get you pretty far (in fact the first result for this looked pretty good at a glance). Beej's guide is also a pretty good overview of sockets, but isn't focused on IPC.
|
# ? Feb 2, 2009 23:11 |
|
What about memory-mapped files?
|
# ? Feb 3, 2009 00:14 |
|
What about named pipes? edit: here's the list of the IPC methods that Windows supports: http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx
|
# ? Feb 3, 2009 00:37 |
|
Ive got an object that has a private variable of string. I was told to do this: class Foo { private: const std::string playerName; public: Foo(const std::string& _playerName) :playerName(_playerName) { } }; Is there a better way to do this?
|
# ? Feb 3, 2009 05:30 |
|
Do what?
|
# ? Feb 3, 2009 06:09 |
|
Avenging Dentist posted:Do what? I assume set playername from the constructor argument, the question being should you use an initialization list, and the answer being yes.
|
# ? Feb 3, 2009 09:08 |
|
Errr sorry i was exhusted when i wrote that. Basically we have an object that needs to store a string, this string will never change. So is the way above the best way to do this?
|
# ? Feb 3, 2009 15:05 |
|
UberJumper posted:Errr sorry i was exhusted when i wrote that.
|
# ? Feb 3, 2009 16:46 |
|
I'm trying to break some class method definitions out of a header file into their own .cpp file, but for some reason, including the original .h file in this new .cpp file causes the compiler to generate 70 dumb "missing type specifier" errors (and others indicative of compiler confusion) in a completely different header file, and I can't figure out why. I don't even have to have any code at all in the new .cpp file for the problem to occur; just a single line: #include "ProblematicHeader.h" will do it. This header is included fine from other files in the project (both other .h and .cpp files), and everything relevant seems to be properly include-guarded. I'm completely at a loss for how to even start figuring out what's wrong.
|
# ? Feb 3, 2009 22:27 |
|
GrumpyDoctor posted:I'm completely at a loss for how to even start figuring out what's wrong. So are we because you didn't post any code. I don't know, maybe make sure that the header isn't using stuff that's declared in another header that you aren't including?
|
# ? Feb 3, 2009 22:31 |
|
Avenging Dentist posted:So are we because you didn't post any code. okay here is the problematic code code:
|
# ? Feb 3, 2009 23:02 |
|
Which is worse, an Avenging Dentist or a Grumpy Doctor?
|
# ? Feb 3, 2009 23:22 |
|
Mustach posted:Which is worse, an Avenging Dentist or a Grumpy Doctor? Which is worse at programming?
|
# ? Feb 4, 2009 01:10 |
|
GrumpyDoctor posted:And yes, that was the problem. For some reason GSTTypes.h doesn't include everything it needs. I am still learning my way around some of these compiler errors I guess! Are you sure you just don't have your includes set up in a different directory structure than GSTTypes.h is expecting?
|
# ? Feb 4, 2009 09:03 |
|
Thug Bonnet posted:Are you sure you just don't have your includes set up in a different directory structure than GSTTypes.h is expecting? Yeah, unless I'm misunderstanding you. Everywhere else GSTTypes.h was included, there were two other includes just before it, and if I included GSTTypes.h without these includes as well, GSTTypes.h wouldn't compile, but the compiler wouldn't figure this out until it was trying to put some other file together. Moving those includes into GSTTypes.h itself fixed the problem.
|
# ? Feb 4, 2009 21:05 |
|
Can someone tell me why this isn't seeing the EOF once it reaches the end? http://pastebin.com/m2db6e2ec When I first ran it, it entered an infinite loop of 0's, so I put a getchar() in there and saw that it's not seeing the end of file, so it gets stuck in the inner while loop, since there is obviously no sentinel after the EOF.
|
# ? Feb 5, 2009 02:05 |
|
Anunnaki posted:Can someone tell me why this isn't seeing the EOF once it reaches the end? The EOF flag is only updated after you try to read from a file past the EOF. It looks like that might be your problem.
|
# ? Feb 5, 2009 02:24 |
|
Anunnaki posted:Can someone tell me why this isn't seeing the EOF once it reaches the end? it is entirely possible that you're hitting eof between the first check and your inner while loop. your inner while loop should be testing for eof, too. Also, it is generally a bad idea to mix C (getchar) and C++ I/O (iostreams stuff) calls. Edit: Wait, you do know that getchar() reads only from stdin, right? floWenoL fucked around with this message at 02:36 on Feb 5, 2009 |
# ? Feb 5, 2009 02:31 |
|
floWenoL posted:it is entirely possible that you're hitting eof between the first check and your inner while loop. your inner while loop should be testing for eof, too. Oh, okay, I just added an if statement within the loop to check for the EOF, and it works now. Thanks. Also, I'm using getchar() because it doesn't need another library (like _getch()). Is there another one I can use? Edit: VVVVVV Awesome, thanks. Cosmopolitan fucked around with this message at 03:05 on Feb 5, 2009 |
# ? Feb 5, 2009 02:39 |
|
Anunnaki posted:Also, I'm using getchar() because it doesn't need another library (like _getch()). Is there another one I can use? iostream::get
|
# ? Feb 5, 2009 02:40 |
|
Hi CoC, I'm trying to use CImg to grab a section of my desktop screen on a Windows XP machine. There's got to be a better way than using the Windows API to take a screenshot, save it to a bmp and then load it with CImg. Any ideas on how I should go by doing this? Hopefully in a very quick way that avoids the hard drive.
|
# ? Feb 5, 2009 03:36 |
|
FearIt posted:Hi CoC, Surely you have access to the bitmap in memory before you dump it to disk? CImg has constructors that take in a raw bitstream and reads it given dimensions, stride, and color format. It looks like the Win32 API functions return a 24-bit bitmap, so it should be fairly straightforward to get the necessary params from the bitmap header and pass them to CImg.
|
# ? Feb 5, 2009 03:50 |
|
I'm trying to figure out how to fix Boost.Optional's InputStreamable implementation. What I mean is, I think any given optional type should behave as much like the type it wraps as possible. For example:code:
code:
code:
code:
So c++ gurus, does this idea seem reasonable? Else on a scale from 1 to 10 (with 10 being Whitesmiths style indentation) how horrible is my code? Lexical Unit fucked around with this message at 21:31 on Feb 5, 2009 |
# ? Feb 5, 2009 05:43 |
|
floWenoL posted:Surely you have access to the bitmap in memory before you dump it to disk? CImg has constructors that take in a raw bitstream and reads it given dimensions, stride, and color format. It looks like the Win32 API functions return a 24-bit bitmap, so it should be fairly straightforward to get the necessary params from the bitmap header and pass them to CImg. Yeah you can get the DIB rather than write it to disk iirc.
|
# ? Feb 5, 2009 07:01 |
|
int ival = 65; int iaddr = (int) &ival; for(int i = 0; i < sizeof(int); i++) { printf("%08x: %02x\n", (iaddr + i), (* (char*)(iaddr + i))); } I was given this piece of code and I am supposed to explain what its doing, I understand that its printing the address of ival in hex to 8 places. but I don't understand what (* (char*)(iaddr + i)) is doing. What does * (char*) mean? What is it doing?
|
# ? Feb 5, 2009 21:18 |
|
Not even compile is what it does Edit: Assuming C99, it segfaults.
|
# ? Feb 5, 2009 21:21 |
|
It's clearly supposed to print out each byte of ival by doing some pointer casts, but they screwed up the position of the (char *) cast, so instead it accesses undefined memory.
|
# ? Feb 5, 2009 22:25 |
|
ShoulderDaemon posted:It's clearly supposed to print out each byte of ival by doing some pointer casts, but they screwed up the position of the (char *) cast, so instead it accesses undefined memory. Actually that's not true at all. The address of ival is cast to an int, so iaddr+1 refers to one byte past iaddr, not one word past. The code should actually work on 32-bit systems, but will crash on a 64-bit system because int isn't large enough to hold a pointer.
|
# ? Feb 5, 2009 22:30 |
|
Avenging Dentist posted:Actually that's not true at all. The address of ival is cast to an int, so iaddr+1 refers to one byte past iaddr, not one word past. Last I checked, iaddr+1 might as well refer to your mom. You do not get to do pointer arithmetic on things that are not pointers.
|
# ? Feb 5, 2009 22:32 |
|
Vanadium posted:Last I checked, iaddr+1 might as well refer to your mom. You do not get to do pointer arithmetic on things that are not pointers. If you mean that strictly speaking it's undefined under the standard, then yes, this is invalid because you are attempting to read an object through a pointer of incompatible type; there is no reason why a C implementation couldn't arbitrarily declare that all accesses through int* will actually be offset by 17 bytes because of spite. If you mean that there are implementations of the standard where this won't work for reasons other than AD's point that they should be using intptr_t, well, I would be fascinated to see a constructive proof of your statement.
|
# ? Feb 5, 2009 22:38 |
|
Also,ISO/IEC 9899:1999 6.3.2.3 posted:5. An integer may be converted to any pointer type. Except as previously specified, the result is implementation-defined, might not be correctly aligned, might not point to an entity of the referenced type, and might be a trap representation.56 So this is, necessarily, a discussion of implementations, not specifications.
|
# ? Feb 5, 2009 22:41 |
|
I think that I've got a pointer in my code screwing things up. The thing is, it's not causing a segmentation error, its probably corrupting something inside my app's own memory space and is affecting data in such a way that the app does not break, rather than behave weirdly. Is there a tool a-la valgrind that makes sure that when ever a pointer is used to access something, that something actually matches the pointer's type? Any other tips and tricks on diagnosing these kinds of errors in a big-ish app? (a few thousand lines of code).
|
# ? Feb 6, 2009 16:51 |
|
Alright I have a quick question that is really annoying me. Say I have a 16 bit number, and I need to get bits 10-13, how do I do this? I was thinking that I could do x >> 10 & 0xD but that isn't working.
|
# ? Feb 8, 2009 02:47 |
|
Super Dude posted:Alright I have a quick question that is really annoying me. Say I have a 16 bit number, and I need to get bits 10-13, how do I do this? I was thinking that I could do x >> 10 & 0xD but that isn't working. 0xD is binary 1101, you meant 0xF which is binary 1111. If you have boost, you don't have to worry about messing stuff like this up since you can just do BOOST_BINARY( 1111 ) to get your mask.
|
# ? Feb 8, 2009 03:08 |
|
Super Dude posted:Alright I have a quick question that is really annoying me. Say I have a 16 bit number, and I need to get bits 10-13, how do I do this? I was thinking that I could do x >> 10 & 0xD but that isn't working. I'm not sure what you mean to do with what you've got so far, but it sounds like what you want to do is make a mask. Draw out 16 bits and set 0's on the bits you don't want and 1's on the bits you do want: 00000000 00111100 That comes out to 0x3c . Then use bitwise and to get just the bits you want: unsigned short goodBits = mask & val; You can check if a given bit is set similarly: bool isSet = (0x8000 >> bitNumToCheck) & val; efb :P Also, is there a place where all these awesome Boost features are cataloged? julyJones fucked around with this message at 03:16 on Feb 8, 2009 |
# ? Feb 8, 2009 03:11 |
|
julyJones posted:Also, is there a place where all these awesome Boost features are cataloged? Yes, the Boost documentation. Where else would it be?
|
# ? Feb 8, 2009 03:24 |
|
|
# ? Apr 19, 2024 05:00 |
|
julyJones posted:Also, is there a place where all these awesome Boost features are cataloged? Here? BOOST_BINARY is documented here.
|
# ? Feb 8, 2009 03:26 |