|
#ifdef _MSC_VER // We'll also define this to stop MSVC complaining about sprintf(). #define _CRT_SECURE_NO_WARNINGS #pragma comment(lib, "Irrlicht.lib") #endif #include <irrlicht.h> #include <iostream> #include <fstream> #include <iomanip> #include <string> using namespace irr; using std::string; I know I said I was using iostream.h, but in truth I was using iostream. I had been able to figure out the h was depreciated by myself. Strangely enough I do have to use it for irrlicht. Originally I was able to get the irrlicht tutorials to work, except when I used std::cout, or std::cin. I eventually realized I needed to click the box under Build options, Compiler Flag, 'single-threaded run time library' [/Ml] or 'single-threaded debug runtime library' [Mld] If I'm already using namespace for irr, can I also do 'using namespace std;' so I don't have to put a std:: in front of every cout and cin? About being able to open and edit a textfile in MSVC, what tutorial would you guys recommend?
|
# ? Aug 16, 2009 15:13 |
|
|
# ? Apr 29, 2024 15:55 |
|
Avenging Dentist posted:Hahahahahahahahaha no. These two headers have nothing to do with one another. (string.h is cstring in C++) What are the differences between a CString and a string usage wise? Is one better then the other? Like I know you do things differently with CStrings and strings, but are they two means to the same end?
|
# ? Aug 16, 2009 16:44 |
|
There is no thing named CString in the standard library. Edit: The <cstring> header repackages the C89 string.h functionality within the std namespace, so it is basically C strings, it does not actually introduce anything like a CString type. The <string> header gives you the std::string type. Vanadium fucked around with this message at 16:52 on Aug 16, 2009 |
# ? Aug 16, 2009 16:48 |
|
Vanadium posted:There is no thing named CString in the standard library. Edit: ah I see
|
# ? Aug 16, 2009 16:55 |
|
There are three completely different string datatypes being talked about here:
|
# ? Aug 16, 2009 17:34 |
|
I've got a bit of a debugging question here. My program compiles fine, and at first seems to run well. However, whenever I try and close it I get an unhandled exception error. This isn't unusual. What's unusual is that I've gone through using breakpoints, and the error doesn't occur until AFTER my main() function returns. Is this from a deconstructor being called? How do I locate a problem like this? I also get another error after the first; "No symbols are loaded for any call stack frame. The source code cannot be displayed."
|
# ? Aug 16, 2009 19:39 |
|
Standish posted:There are three completely different string datatypes being talked about here: Also, this CString.
|
# ? Aug 16, 2009 20:09 |
|
floWenoL posted:Also, this CString. I just concatenated in my pants.
|
# ? Aug 16, 2009 20:47 |
|
Avenging Dentist posted:What are some of the other errors? The only time the piece of code you gave me seems to do anything is when I put it right after #include stdafx.h but right before the other #includes. When I do this, it gives me like 200 errors that mostly read "error C4430: missing type specifier - int assumed. Note: C++ does not support default-int." I tried the windows.h thing and that gives me an error that says " fatal error C1189: #error : WinSock.h has already been included." Bleh. :\
|
# ? Aug 17, 2009 20:34 |
|
HondaCivet posted:The only time the piece of code you gave me seems to do anything is when I put it right after #include stdafx.h but right before the other #includes. When I do this, it gives me like 200 errors that mostly read "error C4430: missing type specifier - int assumed. Note: C++ does not support default-int." Did you create this project yourself or are you working with someone else's stuff? MSVC's precompiled headers (that's what stdafx.h is for) are just a gigantic clusterfuck and almost always make your life worse. I've never been able to get them to work sensibly, though to be fair I haven't tried especially hard. If I'm using MSVC, I always create a blank project and do everything from scratch. Believe me, it's easier. It would probably be faster if I just took a look at it in person though. Avenging Dentist fucked around with this message at 20:49 on Aug 17, 2009 |
# ? Aug 17, 2009 20:43 |
|
Avenging Dentist posted:Did you create this project yourself or are you working with someone else's stuff? MSVC's precompiled headers (that's what stdafx.h is for) are just a gigantic clusterfuck and almost always make your life worse. I've never been able to get them to work sensibly, though to be fair I haven't tried especially hard. It's something the company made but they might be lazy and are using the default. Look out for a PM.
|
# ? Aug 17, 2009 21:15 |
|
Is there a common means of generating a public interface header for a library from multiple headers? For example my library has multiple source files, and multiple headers, and ultimately I'd like to have a single header to include that describes the interface rather than the handful of separate headers.
|
# ? Aug 18, 2009 19:28 |
|
Thug Bonnet posted:Is there a common means of generating a public interface header for a library from multiple headers? For example my library has multiple source files, and multiple headers, and ultimately I'd like to have a single header to include that describes the interface rather than the handful of separate headers. Make a header that includes the other headers?
|
# ? Aug 18, 2009 19:32 |
|
Adhemar posted:Make a header that includes the other headers? That's one solution, but it's not very pleasant. I know there are utilities to do this, I just don't know what they are.
|
# ? Aug 18, 2009 19:34 |
|
Thug Bonnet posted:That's one solution, but it's not very pleasant. I know there are utilities to do this, I just don't know what they are. Why is that not pleasant? That's what you do. Or, if you're some kind of obsessive weirdo, you could just make said header file and run gcc -E on it.
|
# ? Aug 18, 2009 19:45 |
|
Avenging Dentist posted:Or, if you're some kind of obsessive weirdo, you could just make said header file and run gcc -E on it. I am, and that's exactly what I was looking for. Thanks
|
# ? Aug 18, 2009 19:53 |
|
Thug Bonnet posted:I am, and that's exactly what I was looking for. Thanks What's the advantage of doing it this way? It would have to outweigh the fact the you're duplicating code.
|
# ? Aug 18, 2009 20:42 |
|
Thug Bonnet posted:That's one solution, but it's not very pleasant. I know there are utilities to do this, I just don't know what they are. If you're worried about remembering to add the includes, it's easy enough to write a script that generates the mondo-header & add it to your build process: code:
|
# ? Aug 18, 2009 21:39 |
|
I've got a possibly stupid question for you c geniuses. I've written a small program which loads data from a file into a linked list etc etc, standard uni assignment stuff. The program compiles and runs fine on my home linux computer, but when running it on the schools computer (Solaris), the program shits its pants with a bus error when trying to traverse the list. According to GDB it doesn't like: code:
The program compiles fine on both systems with -ansi -pedantic -Wall flags, and like I said, it works fine on Linux. Any help would be appreciated.
|
# ? Aug 19, 2009 03:21 |
|
does it throw the bus error immediately (ie. the first time through the loop) or does it get part way through the traversal before it crashes? Either way, it sounds like your routine for building your list is maybe stomping on memory somewhere, or something's misalligned, or something like that. (I would venture it's an x86 vs sparc issure as opposed to a Linux vs Solaris one.) edit: Do me a favour and set a breakpoint and inspect what listptr points to. If it's an invalid region of memory, it should say. Dijkstracula fucked around with this message at 03:47 on Aug 19, 2009 |
# ? Aug 19, 2009 03:44 |
|
Solved it. Turns out I wasn't initializing the head pointer to null. loving dumb thing to waste a whole morning on. Thanks for your help Dijkstracula.
|
# ? Aug 19, 2009 04:50 |
|
So I'm going for a fresh build of the newest GCC: gmp-4.2.4 mpfr-2.4.1 gcc-4.4.1 "make check" and "make install" on gmp and mpfr go fine, libraries are present and everything seems to be working. Running ./configure in GCC fails however, and complains the mpfr isn't the right version. When I tell it where to find the .h file just created via the make install, it complains the gmp is the wrong version (which it doesn't do when I don't specify mpfr). quote:checking for correct version of gmp.h... yes Any thoughts on how to proceed?
|
# ? Aug 19, 2009 09:51 |
|
quadreb posted:So I'm going for a fresh build of the newest GCC: run ldconfig as root?
|
# ? Aug 19, 2009 14:37 |
|
C99 Question: I've got the following union: code:
edit: For reference, I am using the __STDC_IEC_559__ macro that AD mentioned on the previous page to verify that the float and double aren't crazy. edit2: I know it sounds like I'm being paranoid, so let me give a few more details to explain why I'm being so cautious. The data files this program reads are scientific instrument recordings spanning about 4-5 years in the early 90s. I'm in the process of packaging that data up to put into a long term storage computer. In addition this program I'm writing will be sitting next to the data. What will most likely occur is no one will use this program for a decade or more (if ever). I'm trying to make it as likely as I can that this program will still function then, or give enough information so that a researcher, who will almost certainly have minimal programming experience, can still access the data or hand the program off to someone to update it so they can access the data. 6174 fucked around with this message at 19:33 on Aug 19, 2009 |
# ? Aug 19, 2009 19:02 |
|
In general, it's not a reasonable expectation, but in your case, it should be okay. On certain architectures, alignment requirements would pad out the array if sizeof(yourtype) wasn't a multiple of the alignment stride. However, since all those datatypes will be naturally 4-byte aligned (which is the only alignment that I've seen in use these days), that shouldn't pose a problem for you. If you know something about the compiler that will be used, you can use a directive like __attribute__ ((__packed__)) on a union, but I've never actually needed this, so I can't tell you how the behaviour would play on different architectures. Also scientific code
|
# ? Aug 19, 2009 21:03 |
|
Dijkstracula posted:If you know something about the compiler that will be used, you can use a directive like __attribute__ ((__packed__)) on a union, but I've never actually needed this, so I can't tell you how the behaviour would play on different architectures. quote:Also scientific code
|
# ? Aug 19, 2009 21:14 |
|
BigRedDot posted:OH you don't even know. I mean, unless you do.
|
# ? Aug 19, 2009 21:26 |
|
Dijkstracula posted:In general, it's not a reasonable expectation, but in your case, it should be okay. Yeah, certainly alignment in general can't be assumed, but for the types in this particular union it seemed like a reasonable expectation. Dijkstracula posted:If you know something about the compiler that will be used, you can use a directive like __attribute__ ((__packed__)) on a union, but I've never actually needed this, so I can't tell you how the behaviour would play on different architectures. Unfortunately I've got no clue what compilers will be common in the future. For now I'm using gcc, and trying to keep from using any odd extensions and attempting to make explicit the various assumptions I'm making. Dijkstracula posted:Also scientific code This will be at least the 3rd or 4th generation of this program (others not written by me, and don't completely work with modern compilers if they ever worked), but it will be the first to have any comments or error checking.
|
# ? Aug 19, 2009 22:11 |
|
6174 posted:Yeah, certainly alignment in general can't be assumed, but for the types in this particular union it seemed like a reasonable expectation. Honestly, if you test this with, say, gcc and icc, in 32-bit x86 and amd64/x86_64 envionments, I would say it's highly likely that it will work for the forseeable future.
|
# ? Aug 19, 2009 22:23 |
|
Okay I never wrote anything where alignment or padding or whatever mattered but would it not be safer and more intuitive to just stuff everything into a char[512] instead of hoping that your unions are not going crazy on you
|
# ? Aug 19, 2009 23:14 |
|
Dijkstracula posted:Oh I know. My favourite was a fluid dynamics app that, as part of the build process, had to build its own copy of gcc. Getting that one to comiple with Intel compilers was a comically huge amount of work. LOL that's awesome, I hope that was 10 years ago. Building gcc 2.x was a blast in the 90's Edit: I still think it would be amusing to start with the latest gcc release, compile the immediately previous release, and repeat this process for as long as it works. I wonder what the absolute oldest version of gcc you could get to build today is. BigRedDot fucked around with this message at 23:19 on Aug 19, 2009 |
# ? Aug 19, 2009 23:17 |
|
BigRedDot posted:LOL that's awesome, I hope that was 10 years ago.
|
# ? Aug 19, 2009 23:40 |
|
6174 posted:The reason I ask is because my program verifies it to be 512, and gives an error if it is not. I just want to be sure that is a reasonable expectation on my part. Are you checking at compile-time or at run-time? If you're compiling it now to be used 10 years from now, then if you do a compile-time check you'll know that whenever you run it it'll still work.
|
# ? Aug 20, 2009 00:56 |
|
floWenoL posted:Are you checking at compile-time or at run-time? If you're compiling it now to be used 10 years from now, then if you do a compile-time check you'll know that whenever you run it it'll still work. Vanadium posted:Okay I never wrote anything where alignment or padding or whatever mattered but would it not be safer and more intuitive to just stuff everything into a char[512] instead of hoping that your unions are not going crazy on you 6174 fucked around with this message at 01:35 on Aug 20, 2009 |
# ? Aug 20, 2009 01:18 |
|
6174 posted:It is currently run-time because sizeof won't work as part of a pre-processor command, and I don't know of an alternative means to check the size of the union at compile-time. Also, it won't be the binary that is distributed, but the source. I didn't mean checking it with the preprocessor but a static assertion, which is something like (untested): code:
code:
You should probably do it anyway, even if you're distributing the source, so that if it does break, you'll know it early. Edit: Source: http://pera-software.com/articles/compile-time-assertions.pdf floWenoL fucked around with this message at 01:32 on Aug 20, 2009 |
# ? Aug 20, 2009 01:30 |
|
floWenoL posted:You should probably do it anyway, even if you're distributing the source, so that if it does break, you'll know it early. I haven't seen static asserts like that in C before. I'll definitely be adding those checks.
|
# ? Aug 20, 2009 01:38 |
|
Can anyone tell me how to edit a string of numbers? I have so far int string[7]; scanf("%s", string); a = string [0]; printf("a is %i\n", a); But all I get is random numbers for a. Assuming I have all the correct syntax, it should display element 0 of my string array right?
|
# ? Aug 22, 2009 23:23 |
|
%s is for strings, not for int arrays. I am pretty sure there is no format specifier that lets you read multiple integers at once.
|
# ? Aug 22, 2009 23:37 |
|
Vanadium posted:%s is for strings, not for int arrays. I am pretty sure there is no format specifier that lets you read multiple integers at once. code:
code:
|
# ? Aug 23, 2009 00:35 |
|
|
# ? Apr 29, 2024 15:55 |
|
I meant something that is to %d as %s is to %c
|
# ? Aug 23, 2009 00:41 |