|
Argh - yeah, I figured it would be easier talking as though they were int positions Anyway in the first case, simplest would be just wait until randoms has 1000 entries, like: code:
I am also assuming the OP is a beginner trying to get their head around how the lists work, not actually coding anything useful, so I was aiming for simplicity (& missed?)
|
# ? Aug 13, 2013 10:25 |
|
|
# ? Jun 7, 2024 05:22 |
|
rhag posted:Has anyone ever used libunrar (from https://github.com/vilkov/libunrar)? You're not allowed to. pre:Unrar source may be used in any software to handle RAR archives without limitations free of charge, but cannot be used to re-create the RAR compression algorithm, which is proprietary. Distribution of modified Unrar source in separate form or as a part of other software is permitted, provided that it is clearly stated in the documentation and source comments that the code may not be used to develop a RAR (WinRAR) compatible archiver.
|
# ? Aug 13, 2013 11:27 |
|
Suspicious Dish posted:You're not allowed to. Hm? Doesn't that say you can't use it to create RAR's, but it's okay to use it to uncompress them? It's a little confusing.
|
# ? Aug 13, 2013 11:54 |
|
Oh, yeah, that's confusing. I'm assuming that an "archiver" tool is one that uncompresses RARs, but I'm not sure.
|
# ? Aug 13, 2013 12:02 |
Suspicious Dish posted:Oh, yeah, that's confusing. I'm assuming that an "archiver" tool is one that uncompresses RARs, but I'm not sure. Nah, in traditional terms the archiver creates archives, the unarchiver unpacks. From a business point of view, the idea of libunrar is to let anyone integrate support for reading and unpacking RAR files into their software, in the hope that having wide support for the format creates more demand for selling WinRAR to create the files.
|
|
# ? Aug 13, 2013 12:33 |
|
There are a lot of open source programs out there (7z for example) that can and do uncompress rar files. Won't create them, but can extract them. I'll go study them to see how do they do it, but I was kinda hoping for some obvious mistake that I'm doing that will let me extract multi volume archives without too much fuss. The unrar binary is quite convoluted.
|
# ? Aug 13, 2013 13:14 |
|
rhag posted:There are a lot of open source programs out there (7z for example) that can and do uncompress rar files. The last time I checked, 7z required that you have the external unrar program on your machine (it came bundled with it on Windows), but since then it seems it's got a native implementation of it. Possibly clean room engineered? It doesn't seem to use any unrar code though.
|
# ? Aug 13, 2013 13:42 |
|
OzyMandrill posted:Argh - yeah, I figured it would be easier talking as though they were int positions Your assumption is correct. I changed my first for loop to use your while loop, but now the code just spits out a bunch of 0s.
|
# ? Aug 13, 2013 13:48 |
|
Can anyone explain what the extension or the proposed (and later removed I suppose?) C++0x operator typeof does? For the latter what it was replaced with in C++11 and why? I was working on Google's breakpad compiling it with Clang 3.4 and it puked over a typeof specifier. And I admit it's a corner of C++ I hadn't touched yet.
|
# ? Aug 13, 2013 14:25 |
|
typeof is a nonstandard extension. Are you looking for typeid or decltype?
Posting Principle fucked around with this message at 14:32 on Aug 13, 2013 |
# ? Aug 13, 2013 14:29 |
|
Posting Principle posted:typeof is a nonstandard extension. Are you looking for typeid or decltype? No, I'm talking about typeof, hence calling it an extension in the first part of the sentence. But in double checking the pedantry I came across http://lifecs.likai.org/2009/11/emulating-c0x-auto-keyword-in-c.html that answered the question. I wonder now why I couldn't find that page yesterday.
|
# ? Aug 13, 2013 14:40 |
|
Hughlander posted:Can anyone explain what the extension or the proposed (and later removed I suppose?) C++0x operator typeof does? For the latter what it was replaced with in C++11 and why? I was working on Google's breakpad compiling it with Clang 3.4 and it puked over a typeof specifier. And I admit it's a corner of C++ I hadn't touched yet. decltype is the C++11 replacement. IIRC the name was chosen so that it didn't conflict with the existing extensions. If you're using C++11, you should probably prefer decltype to typeof.
|
# ? Aug 13, 2013 14:54 |
|
The name was changed to decltype because the semantics ended up being different than typeof, so just blindly replacing typeof with decltype may not work out if references are involved.
|
# ? Aug 13, 2013 15:44 |
|
Ok, I figured out the last problem, but now I'm having trouble using ifstream to read strings from a file. I have a file, sentence.dat, that contains "the quick brown fox jumps over the lazy dog". The eventual goal (as before, I'm a beginner just learning how to use stuff) is to turn that file into a list of strings, then remove any instance of a given string. Here's what I have so far, but MSVC 2010 is throwing an error at the >> operator:code:
|
# ? Aug 13, 2013 16:58 |
hooah posted:Ok, I figured out the last problem, but now I'm having trouble using ifstream to read strings from a file. I have a file, sentence.dat, that contains "the quick brown fox jumps over the lazy dog". The eventual goal (as before, I'm a beginner just learning how to use stuff) is to turn that file into a list of strings, then remove any instance of a given string. Here's what I have so far, but MSVC 2010 is throwing an error at the >> operator: You haven't assigned anything to i at the point you are reading in strings, so you are effectively trying to put the contents of word into an unknown place. When you want to continually add items to a container like that you should generally use the container.push_back(element) function rather than iterators. (There is also something called a back-inserter iterator, but you probably shouldn't worry about those just yet.) Something like this: C++ code:
|
|
# ? Aug 13, 2013 17:09 |
|
Warnings were already enabled, but I didn't notice one for that (which may just be because the error that MSVC throws is so verbose I didn't see a warning). I changed to using push_back, but still get an error on the "while" line. The error says that "no operator is found which takes a left-hand operand of type 'std::ifstream' (or there is no acceptable conversion".
|
# ? Aug 13, 2013 17:57 |
|
I thought the idea behind decltype was because typeof might be ambiguous in meaning static or dynamic type.
|
# ? Aug 13, 2013 22:20 |
|
Is there any reason for doing something like this?code:
|
# ? Aug 15, 2013 10:10 |
|
hooah posted:Warnings were already enabled, but I didn't notice one for that (which may just be because the error that MSVC throws is so verbose I didn't see a warning). I changed to using push_back, but still get an error on the "while" line. The error says that "no operator is found which takes a left-hand operand of type 'std::ifstream' (or there is no acceptable conversion". I think the problem is because you are trying to do: code:
However, there is no acceptable conversion from an object reference to a bool which is what the while() needs. I'm not very good at stream stuff myself, but I think it would need something like this: code:
|
# ? Aug 15, 2013 11:59 |
|
OzyMandrill posted:I think the problem is because you are trying to do:
|
# ? Aug 15, 2013 12:18 |
|
Strabo posted:Is there any reason for doing something like this? This seems to a avoid all the use cases of unions since the variables are all of the same type, and you'd need a separate indicator to tell you what it stores anyway. Maybe it's some sort of future-proofing, in case they decide to also store another data type in there?
|
# ? Aug 15, 2013 12:47 |
|
mobby_6kl posted:This seems to a avoid all the use cases of unions since the variables are all of the same type, and you'd need a separate indicator to tell you what it stores anyway. Maybe it's some sort of future-proofing, in case they decide to also store another data type in there? But then I thought that this may be some super advanced C trick that I don't know about yet
|
# ? Aug 15, 2013 13:09 |
|
The Gripper posted:It's actually much simpler, he forgot to #include <string>. Yeah, this was the problem. That's what I get for taking a month or so break right after my very first programming class and then trying to pick it back up before fall classes start. Edit: In doing some poking, it turns out that MSVS 2010, which I got for free from the school I took my first class from, won't be fully supporting C++ 11. In my hunt, I came across Eclipse, but there's more than one C/C++ version - just Eclipse and Eclipse Indigo. Would either of these be a good choice for something that's (relatively) easy to switch to from MSVS and also fully supports the new standard? If not, what would be another suggestion? hooah fucked around with this message at 22:05 on Aug 15, 2013 |
# ? Aug 15, 2013 13:13 |
|
hooah posted:Yeah, this was the problem. That's what I get for taking a month or so break right after my very first programming class and then trying to pick it back up before fall classes start. Using anything other than Visual Studio for Windows C++ development is going to be some degree of headache or another, and you should only do it if the headache of using Visual Studio is greater. "It doesn't support all of C++11" isn't a headache unless you anticipate needing some specific feature of C++11 that VS2010 doesn't support. Is that the case?
|
# ? Aug 16, 2013 09:15 |
|
GrumpyDoctor posted:Using anything other than Visual Studio for Windows C++ development is going to be some degree of headache or another, and you should only do it if the headache of using Visual Studio is greater. "It doesn't support all of C++11" isn't a headache unless you anticipate needing some specific feature of C++11 that VS2010 doesn't support. Is that the case? I ran into a slight annoyance where VS2010 doesn't have C++11's Delegated Constructors I think. I'm not completely sure so don't quote me on this For those not familiar, it's this syntax: C++ code:
|
# ? Aug 16, 2013 09:21 |
|
I don't foresee any need for anything specific in C++11, but the textbook for one of my fall classes is the 5th edition of C++ Primer, which makes a big deal about being rewritten for the new standard. I was just trying to deal with any headache of switching now vs. continuing along with VS2010 for the time being, only to run into an assignment that requires something from the new standard in the middle of the semester when I have decidedly less time for dicking around.
|
# ? Aug 16, 2013 11:58 |
|
I would be surprised if Programming 201 or whatever exercises the parts of C++11 that VS2010 is missing, but I'm just a guy on the Internet. I would actually consider emailing the professor if you know who it is.
|
# ? Aug 16, 2013 20:32 |
|
Strabo posted:Yeah, that's the only reason I can think of, why somebody would want to do that. I was contemplating posting this in the coding horrors thread, because it's pretty confusing to anyone trying yo understand the code and the rest of the code that this came with was kinda horrible as well. Self documenting code? So you never have to wonder what kind of address "address" is? That's my guess.
|
# ? Aug 17, 2013 04:03 |
|
sund posted:Self documenting code? So you never have to wonder what kind of address "address" is? That's my guess. If I want to pass a var from an early function I've Tbh, the existence of a var called 'extend_address' is probably due to someone doing exactly the same thing, but early enough in the dev process that they could add a whole var. Roll on a couple of years and a few tens of extra possible code paths & functions & you could be easily stuffed. Doing it like this when you know others will be poking away at the codebase is 'safer' than just wanging it in a generic 'extra' field, and 'politer' in that not only should they notice this var is being 'reused', but you may even be able to track down in CVS who added the latest 'overload' & buggered up the one you did 3 months ago...
|
# ? Aug 17, 2013 17:52 |
|
edit: gently caress it
tractor fanatic fucked around with this message at 06:19 on Aug 18, 2013 |
# ? Aug 18, 2013 06:05 |
|
Does calling a function allow strict aliasing violations, even if the function is inlined? i.e. if I write this:code:
OneEightHundred fucked around with this message at 00:09 on Aug 19, 2013 |
# ? Aug 18, 2013 23:57 |
|
That's UB even without the inlining, so no, it's not guaranteed.
|
# ? Aug 19, 2013 00:27 |
|
How would I track the real execution time of a program in C without using the shell time command, or using clock()? My program runs a lot longer than the 2147 seconds I can get out of clock() (and I can't poll mid run), and I can't figure out for the life of me how to use the time_t I get from time() and difftime() to print a human-readable difference (rather than some time a few hours since 1/1/1970, that is).
|
# ? Aug 20, 2013 23:24 |
|
Ciaphas posted:How would I track the real execution time of a program in C without using the shell time command, or using clock()? My program runs a lot longer than the 2147 seconds I can get out of clock() (and I can't poll mid run), and I can't figure out for the life of me how to use the time_t I get from time() and difftime() to print a human-readable difference (rather than some time a few hours since 1/1/1970, that is). code:
|
# ? Aug 20, 2013 23:59 |
|
Blarg, I guess I should have realized time_t is just an int typedef. I'm not thinking too well today. Thanks
|
# ? Aug 21, 2013 01:08 |
|
Ciaphas posted:Blarg, I guess I should have realized time_t is just an int typedef. I'm not thinking too well today. Thanks It's technically legal for time_t to be a typedef to float or double
|
# ? Aug 21, 2013 01:18 |
|
b0lt posted:It's technically legal for time_t to be a typedef to float or double I hate this/these loving language(s).
|
# ? Aug 21, 2013 03:04 |
|
Even if it is, casting to an int will convert the number (possibly with rounding errors).
|
# ? Aug 21, 2013 04:00 |
|
OneEightHundred posted:Does calling a function allow strict aliasing violations, even if the function is inlined? i.e. if I write this: You should be able to use memcpy() for that; any sane compiler will optimize the function call away to do what you want: http://gcc.godbolt.org/#%7B%22versi...B0x%22%7D%5D%7D
|
# ? Aug 21, 2013 13:43 |
|
|
# ? Jun 7, 2024 05:22 |
|
Ephphatha posted:Even if it is, casting to an int will convert the number (possibly with rounding errors). I don't think so. Even if the void* types of the inline function parameters are discarded, he is still casting the pointer types to int* and then dereferencing the value, not casting the values directly. That shouldn't do any conversions or rounding.
|
# ? Aug 21, 2013 14:26 |