|
duck monster posted:Whats the [] square brackets do? (Excuse the dumb questions, I'm reteaching myself C++ after nearly a couple of decades away from the language, and C++11 seems to introduce quite a few new ideas. (I'm in love with the iiterator based for syntax!) The square brackets indicate what variables are captured by the lambda, and whether by value or reference. Wikipedia with examples. I found the Wikipedia C++11 page to be a great summary of stuff that changed since I last rode that bike.
|
# ¿ Mar 6, 2014 06:41 |
|
|
# ¿ May 17, 2024 18:21 |
|
UnfurledSails posted:I'm an undergrad on a systems track and I've never done anything besides assignments and projects for classes (all of them in either C or C++11). I'm about to finish a class on operating systems implementing Pintos, and while it's fun and challenging, I have zero ideas about what I can do to feel less worthless as a programmer in the real world. Any advice? Find something interesting on GitHub and fix an outstanding task. Working in other people's code is an important skill, as is going through code review. The Awful iOS app could be a good place if you're into that.
|
# ¿ Mar 7, 2014 01:00 |
|
FamDav posted:tbf if you want to work on a good app you should probably avoid awful Working on good code isn't really the norm, honestly even for me dealing with my own previous stuff. Builds character, or something. Tip, though: if you see pthread_* just back away. Life's too short for raw shared-state multithreading.
|
# ¿ Mar 7, 2014 03:42 |
|
shrughes posted:
Yeah, it's probably too late for you, and someone has to do the dirty work, but if you're looking for something to get started on raw POSIX threading is not a sign of joy. Don't get me wrong, I've done my time (even with linuxthreads, may it rest in agony), I just don't wish it on people. Too many guns for so few feet.
|
# ¿ Mar 7, 2014 03:55 |
|
duck monster posted:Why not use an S-Expression parser for this? Theres a number of decent implementations out on the net. That seems sort of overkill to avoid having to type some nested literals, no? His big problem isn't parsing, it's manipulating the resulting tree.
|
# ¿ Mar 17, 2014 15:41 |
|
Suspicious Dish posted:Pattern matching is a very common operation in Lisp-likes, and usually part of the parser. You can probably do his simplification stuff with template metaprogramming too, but I thought he was a little more constrained that that in terms of what he had to implement Visitor-wise for the assignment. I've written optimizing compilers, but I don't think I've ever seen a parser do meaningful Boolean expression simplification; it's a lot easier to walk the resulting AST, and that lets you use constant propagation and CSE and such to do a more complete job. If I pulled in a s-expr processing library and it started "simplifying" the resulting tree for me, I would make unpleasant sounds. I guess if his syntax exactly matches Lisp, and he wants to hook the reader somehow, but...a lot of work to avoid typing some structure literals and a few pattern matches. Edit: yeah, he inherited an existing class hierarchy Expression representation, so transcoding through a Lisp parser seems unlikely to be a suitable approach. That said, "just use sexps"/"embed a Lisp" are underused approaches to problem solving for sure. Subjunctive fucked around with this message at 04:36 on Mar 18, 2014 |
# ¿ Mar 18, 2014 04:24 |
|
Nippashish posted:Literally the only place this is relevant is if you are processing transactions and your numbers represent actual values of currency that belong to someone. Even banks use floating point numbers for simulations/forecasting. Using double representation also means you really can't use == without epsilon ranges, which is often a source of annoying and hard-to-diagnose bugs. (C.f. the perennial 0.1 + 0.2 == 0.30000000000000004 confusion from JS programmers.) For a lot of stuff, including statistical analysis, there's enough "fuzz" to hide this stuff, but if you're dealing with a small number of inputs then it can be frustrating to manage and display correctly. I'd grab a decimal-arithmetic library and let it do the hard work, personally.
|
# ¿ Mar 18, 2014 20:08 |
|
hooah posted:I want to iterate over each Vertex in the inner vector except the first one. I tried using a for loop, but the condition needs to be a constant expression, so I can't say "go from 1 to [inner vector].size()". How else can I go about this? Go from [inner vector].size() backwards to 1? I may not be understanding the constraint correctly. Or go from begin()+1 to end(), which is more idiomatic I guess.
|
# ¿ Mar 21, 2014 00:53 |
|
Paul MaudDib posted:It's valid to treat the output of an RNG as "N random bits of output", right? So if I have a RNG that outputs a long (64 bits), I can treat that as 2x32 bits? A good PRNG is equally random across all bits (or you would be able to partially predict the bits that are less likely to change). A bad PRNG is probably less balanced, but there are lots of reasons not to use a bad one. "True" randomness like /dev/random will also be equally distributed.
|
# ¿ Mar 24, 2014 21:34 |
|
hooah posted:Since this is due soon, I'd rather not do a major re-write if I don't have to, but I'll keep this in mind. You might also want to just write a routine to print the graph (could use gnuplot format), so that you can verify it, or call it from the debugger when things get weird. Also makes for good record-and-compare for regression testing.
|
# ¿ Mar 25, 2014 17:58 |
|
We just released our custom C/C++ preprocessor, Warp. It had a surprisingly large impact on our build times. https://code.facebook.com/posts/476987592402291/under-the-hood-warp-a-fast-c-and-c-preprocessor/
|
# ¿ Mar 28, 2014 19:34 |
|
GrumpyDoctor posted:People actually use D for things?? Well Andrei obviously does.
|
# ¿ Mar 28, 2014 19:52 |
|
Bonfire Lit posted:printf's %s format specifier also expects a narrow string (aka char*). So when it gets a wide string as its parameter (which is UTF16LE on Windows), it'll output a byte from the string (which will be the least significant byte of the first wide character), and then, since you pass in UTF-16 encoded characters from the ASCII range, the next byte will be a 0x00, at which point printf stops. If you want to print wide strings with printf, you need to use %ls instead of %s. Alternatively, if you want to use iostreams, use std::wcout and drop the asterisk from your argv access. This is such a common bug, it's too bad MSVC doesn't warn for it.
|
# ¿ Apr 4, 2014 21:18 |
|
Tusen Takk posted:Anyone have any idea why it wouldn't be recognising Alumni but it recognises Student? Because you're including Student.h and not Alumni.h (Alumnus, ahem). Unsigned ints are often the right thing; array indices for example tend to fit them. What did you think was wrong with them?
|
# ¿ Apr 8, 2014 02:17 |
|
A stack of things bigger than what you can fit in an unsigned int would be pretty impressive.
|
# ¿ Apr 8, 2014 02:39 |
|
shrughes posted:Unsigned int is the maximal code smell as far as unsignedness goes. I'm curious, why don't you like unsigned int? I use it a fair bit for "unsigned, natural machine word size". I like the "no negatives" documentation element, and using the natural size would keep the compiler from having to generate masking or whatever like you could see with short or whatever (perhaps more historically than now).
|
# ¿ Apr 8, 2014 17:30 |
|
shrughes posted:Or it's being used in places where a size_t would be the correct choice, or a specific choice of uintN_t. Yeah, that's true. Guess I have a decade of habit to reform!
|
# ¿ Apr 8, 2014 19:16 |
|
ExcessBLarg! posted:If the array is hardcoded, I typically compute the number of elements as "sizeof(array)/sizeof(array[0])". Since the result type of the sizeof operator is size_t, then size_t would be the appropriate index type. I think he's asking about the storage type rather than the index type; the latter is size_t all the way IMO.
|
# ¿ Apr 8, 2014 19:18 |
|
shrughes posted:What makes you think char is a signed type? IIRC it's signed on x86 (gcc/llvm/MSVC) and unsigned on ARM by default, because ARM didn't have a sign-extending byte load instruction. Regardless of char's signedness, though, char, unsigned char and signed char are distinct, and char isn't compatible with the other two. Yay C.
|
# ¿ Apr 9, 2014 02:39 |
|
ExcessBLarg! posted:What makes you think that shrughes thinks char is an unsigned type? Only shrughes can settle this burning debate! Edison was a dick posted:It's got the wrong method signature Wrong getline. http://www.cplusplus.com/reference/string/string/getline/ It does consume the delimiter, FWIW. (I'm not sure what's wrong with the code at first glance.)
|
# ¿ Apr 9, 2014 17:55 |
|
Zopotantor posted:Actually, the index type in C++ is ptrdiff_t (13.6.13). Touché. Edison was a dick posted:Yep, hence the comment about being sarcastic. I missed that as sarcasm. But there are no good I/O APIs. It may be impossible.
|
# ¿ Apr 9, 2014 20:52 |
|
It's totally defined behaviour. rooster[100] refers to the address 100 * sizeof int past rooster. The program has to store there. Which is almost certainly where i and j are, on the stack... Edit: what warning does the compiler emit? It's entirely legal to index an array beyond its declared size. You see it commonly in structures with variable-length components at the end. code:
Subjunctive fucked around with this message at 00:09 on Apr 12, 2014 |
# ¿ Apr 12, 2014 00:06 |
|
pseudorandom name posted:Accessing beyond the end of an array is only defined for flexible array members, which can only occur at the end of a struct. Ah, right. Though actually in this specific case it's defined, I believe: C99 sec 5.7 posted:If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined. Edit: bleh, right, not to dereference. I'll get my coat. (I didn't mean to imply that the aliasing of i and j was defined, by any means.) Subjunctive fucked around with this message at 00:34 on Apr 12, 2014 |
# ¿ Apr 12, 2014 00:31 |
|
Tusen Takk posted:I have to write a function template max_generic() that takes as input an array of either int, float, or double, and returns the maximum element in the array. My professor's ppt slides are less than clear on this, and so far everything I've found on the internet is way over my head. I know how to find the max value of an array, but I don't know how to make it so that it can take multiple types. Going by what I read, I guess if you go You want to - declare and initialize temp (be careful how you choose the initial value; imagine an array with all negative values) - make const T[] array and then it looks like it should work.
|
# ¿ Apr 15, 2014 00:38 |
|
Tusen Takk posted:Is there a reason why you replaced < and > with < and >? No, it's a bug in the latest Awful.app. Sorry!
|
# ¿ Apr 15, 2014 00:53 |
|
Tusen Takk posted:I wanted to use a vector but the professor wants an array, and the professor has ppt slides that say you can use -> to insert things into arrays. I have no idea why I thought taking this class would be a good idea, honestly Are you sure that -> thing isn't just pseudocode? Sorry about the array-decl error, got distracted by a bug I introduced into Awful that the [] tripped, and stopped paying attention.
|
# ¿ Apr 15, 2014 01:52 |
|
roomforthetuna posted:Can they be overloaded separately from the regular operators? That could make them A. kind of useful, and B. hilariously confusing. No, they're just alternate spellings, like trigraphs, in case you have a weird character set missing & or { or whatever. e;FB
|
# ¿ Apr 16, 2014 15:53 |
|
Hammerite posted:But assuming you have an editor that does syntax highlighting, there is no issue with "operators looking like identifiers". What editor do you use that highlights the alternative tokens? They're just macros, so either it special-cases things that transitively include iso646.h and handles redefinition properly, or it's expanding macros to find those that work out to single operator tokens. Those both sound like hanging offenses.
|
# ¿ Apr 16, 2014 18:27 |
|
xgalaxy posted:In Xcode or other standard compliant IDE's they are treated like regular operators, not macros, and are highlighted as such. Is that the case only if iso646 is included transitively and nothing is redefined? (In the C case; they're part of the language in C++ but not C IIRC.) Edit: Per http://en.wikipedia.org/wiki/C_alternative_tokens#C.2B.2B Wikipedia posted:The abovementioned identifiers are operator keywords in the ISO C++ programming language and do not require the inclusion of a header file. For consistency, the C++98 standard provides the header <ciso646>. However the latter file has no effect, being empty. Notwithstanding some compilers, such as Microsoft Visual C++, do require the header to be included in order to use these identifiers. Hmm. Subjunctive fucked around with this message at 19:00 on Apr 16, 2014 |
# ¿ Apr 16, 2014 18:57 |
|
Plorkyeran posted:Or it could just have them in the syntax highlighter's hardcoded list of things to highlight and just accept that it'll sometimes highlight things it shouldn't. Syntax highlighters getting edge cases wrong is not at all unusual or a big deal. Yeah, and I guess it can tell identifier from operator most of the time based on context anyway. This bothers me more than it should, I'll do some breathing exercises.
|
# ¿ Apr 16, 2014 20:00 |
|
Suspicious Dish posted:Yes. But if you have a variable named "not", you deserve to get your code broken. Not that uncommon if you're building an AST or similar, in my limited experience. (And "compl" is out of bounds too?)
|
# ¿ Apr 17, 2014 09:41 |
|
fankey posted:I can receive multicast UDP, send/receive unicast UDP and make TCP/HTTP connections without any issues. The only thing that doesn't work is sending multicast UDP. Is this because Bonjour coopts multicast UDP? I remember having weird interactions between DNS and mcast UDP on OS X, but it was a long time ago. (mcast routes weren't set up until Bonjour initialized, and with broken DNS it failed, or something.) I think this is probably an Apple-related thing, but I'm not certain.
|
# ¿ Apr 19, 2014 14:38 |
|
Generally, my best experiences have been: - use VS on Windows, because you get a debugger that work - build from the command line either with nmake or mingw-make - package everything you depend on, including the CRT redist and DirectX installer The mozilla-build package has a pile of stuff all bundled up that can help a lot; it's what Mozilla uses for the Win32 development side of Firefox and friends, and I always start with it now because I get bash and python and the paths all set up etc etc. https://wiki.mozilla.org/MozillaBuild
|
# ¿ Apr 24, 2014 16:30 |
|
Edison was a dick posted:I don't program for windows, but I understand you can cross-compile from Linux to Windows with MinGW. In my experience this is the falsest of economies. Even if you do all your development on Linux, compile on Windows to test and distribute. Please. For the children.
|
# ¿ Apr 24, 2014 19:07 |
|
GrumpyDoctor posted:Yeah, any function that accepts a non-const reference (especially a constructor) is doing something weird, and if its weird behavior is not clearly documented somewhere then you should be very wary. Would this be any better if the reference were const?
|
# ¿ May 7, 2014 20:10 |
|
Second-guessing the compiler's register allocation is a trail of tears, IMO. See what the profiler says, I doubt it'll consider the extra caller-saves unused register pressure to be a big issue.
|
# ¿ May 9, 2014 04:56 |
|
Lemon King posted:I've been working with C/C++ for a few days now and I'm kinda curious about what compiler I should be using. All my experiences with MinGW have ended in tears, and then when I had to use a debugger the tears were of blood. Use MSVC express, drive it from nmake/CMake/gmake/gyp as you choose.
|
# ¿ May 13, 2014 05:17 |
|
nielsm posted:x<int> is a function, not a type, so yes you can't typedef it to something. Or just code:
which should work everywhere?
|
# ¿ May 14, 2014 22:16 |
|
Yes.
|
# ¿ May 30, 2014 13:53 |
|
|
# ¿ May 17, 2024 18:21 |
|
Vanadium posted:This is why exceptions are terrible~ longjmp or go home.
|
# ¿ Jun 7, 2014 16:58 |