|
durtan posted:So would it make sense to create an int variable from the double variable? I think what he's trying to get at is floats don't necessarily behave exactly as you think they will. Generally, it's considered a best practice to store monetary information in fixed point form because $CASHMONIES * $SOME_VAL / $SOME_VAL may not return the desired result. Machine epsilon, etc.
|
# ¿ Feb 22, 2014 01:11 |
|
|
# ¿ May 21, 2024 03:16 |
|
Tusen Takk posted:I ended up emailing the prof who said that he had a feeling it would start to be an issue and that he'll just grade it from VS. You should probably just write standard compliant code and not rely on anything implementation specific. And if your class doesn't support c++0x/c++11 just deal with it and write code that is supported. It shouldn't be too difficult to get your local compiler flags to match your course. Or just remote in for all of your assignments.
|
# ¿ Mar 5, 2014 16:11 |
|
22 Eargesplitten posted:Okay. Looking at a presentation and document about how they made Dungeon Siege, that looks to be what they did, although back when that came out they only had two threads to work with. I've been looking for more, but right now that's all I've found. My current thought is to have two threads in a pool and one thread independent that's dedicated to loading and removing entities. This mod is for Stalker, which isn't technically an open world game, but has zones that take several minutes to run across at a full sprint. If I used std::async, would I still have to do a lot of locking to keep the processes being run from the pool from data racing? I'm thinking I would keep all of the stuff loading and being removed locked, but I'm not sure if the async function does that for you. You should lock or otherwise prevent data races, yes. You have no guarantees that the scheduler won't do exactly what you don't want it to do. From a practical standpoint though, if you know there will be a few minutes between when writing the data should end and reading it back should begin, the likelihood of running into an error is low. But when the solution is so simple, it's hard to see why you wouldn't want to be sure.
|
# ¿ May 13, 2016 17:42 |
|
Chuu posted:Either is fine, compile time strongly preferred. Can you not set up Werror locally? I'd probably do that and then blame the changes..
|
# ¿ May 22, 2016 13:56 |
|
Hubis posted:Well, you could add a "COUNT" value at the end of the enum, then do a static_assert to ensure the enum::COUNT equals whatever number you expect elsewhere in the code. Doesn't catch people dumping things into the enum past count, which seems like the likely place to dump new things into an enum.
|
# ¿ May 22, 2016 14:53 |
|
Doc Block posted:If your application is GPL or LGPL (OP said it's an open source application), then I don't see why you couldn't just put the class files in your project and call it a day. Because the GPL is a legal virus that you may not want your code infected with? You can't just copy pasta code like that without thought.
|
# ¿ Jun 2, 2016 21:10 |
|
Ralith posted:Yes, that is indeed why we have function overloading! Are you really trying to say that templates are generally bad and should be avoided? Because that goes starkly against conventional wisdom and much of the best laid out code I've seen.
|
# ¿ Jun 18, 2016 01:40 |
|
Ralith posted:Introducing new templates is bad should be avoided when it's unnecessary, which is indeed most of the time. Having powerful metaprogramming available is wonderful, but it should always be your last resort, and if that's contrary to your understanding of conventional wisdom I don't know what to say. The only things necessary for most functions are NOR and JMP, maybe some operators for reading/writing memory. That doesn't mean I shouldn't prefer the tools available to me that make things cleaner. Generics are one of the features C++ has over C. I suppose you're also against smart pointers, custom allocators, and other things that generally make life pleasant?
|
# ¿ Jun 18, 2016 02:12 |
|
That could easily be the case. I'm a bit tilted because I just inherited a JavaScript project.
|
# ¿ Jun 18, 2016 02:28 |
|
Xarn posted:Assuming that you want to have a tree of either nodes with parent pointers, or nodes without parent pointers, not mix and match, it is definitely possible, but kinda painful in C++14 (and pre C++14 as well). You will end up writing the code twice, using template specialization. I think you could do it with the policy based design template template parameters outlined in Alexandrescu's Modern C++. Is that what you're referring to, and if so what's coming in 17 (I haven't been keeping up)?
|
# ¿ Jul 8, 2016 13:05 |
|
Love Stole the Day posted:This isn't a question but since there doesn't seem to be a C/C++ megathread to post this in afaik... I wanted to share this really creative C/C++ program that detects with version of C or C++ you compiled it in and outputs different things accordingly: IOCCC is cool and good.
|
# ¿ Jul 24, 2016 17:21 |
|
raminasi posted:Yes, but your wrapping function can be a named function. No need for a lambda. On the other hand, is there a need to name the function if you're only using it there?
|
# ¿ Aug 11, 2016 04:39 |
|
I know in vim you can just do :make and it builds stuff and opens the quick fix. I'd expect ST to provide hooks as well, but I've never used it.
|
# ¿ Aug 19, 2016 04:01 |
|
VikingofRock posted:Is there a standard way to do RAII with temporary files, either in the STL or in boost? I could roll my own, but I'd rather use an accepted approach if possible. This is on unix and has no need for portability with windows, if that matters. You mean like make a file named by a UUID generated in the constructor and then destroy that file in the destructor? Don't really think there's a standard way to do that. Though there are a few standards on generating a UUID and making a RAII UUID-named temp file would be pretty simple. Depending on what you want the file for, you may want some other filelike object instead, like a FIFO.
|
# ¿ Sep 20, 2016 03:49 |
|
VikingofRock posted:I should mention that I actually do need the filename, since I need to pass it to a subprocess. If there's no standard way of doing this, maybe I'll just write an RAII wrapper around mkstemp. Thanks anyways. Are you trying to send data to or from the subprocess? Use a FIFO.
|
# ¿ Sep 20, 2016 05:07 |
|
VikingofRock posted:So as to avoid the XY problem, I'm just gonna type out the full thing I want to do: I want to create a file, write some data to it, and then call a third-party command line utility which takes the name of the file as one of the command line arguments. That process uses the data in the file to do some analysis, and then it prints the result to stdout, which I am then reading and using in my main program. I want to make sure that the file gets deleted so that I don't have a bunch of these cluttering up the filesystem. I'm gonna be doing this O(10,000) times, across O(100) threads, and the program might get killed at any given moment because of the way that job management works on the supercomputer I'm running this on. Pretty sure that's what FIFOs are for. They're like files in the file system except they don't get written to disk so the performance characteristics should be much better. If you're doing this 10k times, it probably matters. https://www.freebsd.org/doc/en_US.ISO8859-1/books/design-44bsd/overview-io-system.html 2.6.1
|
# ¿ Sep 20, 2016 06:18 |
|
ufarn posted:I actually think IDEs make things a lot worse when it comes to picking up a new language. Maybe if it's the first time you try coding and want to move a turtle in different directions, but all the magic involved in creating external classes in C++ is one of the things that really put me off IDEs. I don't have a problem with using them for programming in general, I just don't see the point of programs where you struggle to even find the build button. IDEs make it easy to find the build button. It looks like this: |>
|
# ¿ Sep 26, 2016 13:20 |
|
rjmccall posted:Copy-on-write strings are a really interesting case. ^a good post. Not using std::string (or wstring, ..) has been a pretty strong leading indicator that I'm going to be dealing with a house of horrors. At least for projects started in the past 5-ish years. It's very easy for people to write things that are less performant and more broken when they think dealing with strings is easy and people who wrote the STL are obviously dumb because they read something like that but far more nuanced on the internet once. As with all things, it's not a problem until you've benchmarked. If you aren't in a place where you can benchmark and you don't have a suitable replacement with several years of industrial use behind it, you have better things to be working on than std::string being too slow for your non-extant application.
|
# ¿ Oct 7, 2016 13:16 |
|
Beef posted:Klade's code went from not fitting on my screen to a handful of readable lines, cool. The space after the ( is upsetting. Doubly so because there isn't one after the 0.
|
# ¿ Oct 10, 2016 12:43 |
|
Nehacoo posted:Yeah I am sure that is it, I tested their new version in the hopes that they had improved this, but nope. clang, vim, and at least for small/mid size projects youcompleteme is good, but i'm not sure if it works well with large projects. i also like syntastic. lldb/gdb or whatever graphical frontend thereof you prefer for a debugger
|
# ¿ Dec 7, 2016 17:51 |
|
Slurps Mad Rips posted:We have a several million line code base at work and not a single person uses an IDE. 5 vim users, and one guy using emacs. i like having the docs window pop up if i start tabbing through completion lists though, saves me effort on looking things up on the other screen. if it ever started taking too long, i'd kill it dead though. syntastic is basically magic though as far as i'm concerned and pretty integral to my workflow. i set up my configs ages ago though, so it's partly just that i don't want to look at my vimrc. besides 9/10 times you're doing twee garbage to try to ICE a compiler. of course completion is going to have trouble
|
# ¿ Dec 8, 2016 07:55 |
|
Beef posted:Your business case is that the cost of upgrading to a compute environment from this decade is less than the cost of a certain programming going on a rampage and literally sacrificing security guideline managers on an altar to productivity. has this environment been audited by a trusted party for work in this sector? let me generate 200 hours of meetings to discuss. by the way, this won't impact the ship date, right? moving literally anything into a secure environment takes months of effort. i am incredibly glad i don't deal with that.
|
# ¿ Dec 15, 2016 13:01 |
|
Fergus Mac Roich posted:Anyone know how I can get started debugging an issue with my use of #pragma warning to disable warnings in MSVC? I have blocks in my header files that look like this: Msdn indicated that push syntax is on 1..4 Try #pragma warning(push) #pragma warning(disable:#) Includes #pragma warning(pop)
|
# ¿ Mar 8, 2017 20:21 |
|
baby puzzle posted:I need to write some data in one thread and read it in another. Now, I understand mutexes and all that, but this is not a usual case. I cannot use any kind of mutual exclusion because it is in real-time code (i.e. in an audio-rendering thread which can NEVER EVER wait, allocate, etc). A different solution would be to use a non-blocking queue, which I am using elsewhere successfully, but these values change often enough that a queue or message of any type is not the right solution. try googling around "lock free data structures" and "compare and swap"
|
# ¿ Mar 28, 2017 15:55 |
|
Zopotantor posted:Much as I respect rjmccall, you should always, always use curly brackets with conditionals, loops etc., even if there's only a single statement inside. Google "goto fail" if you want to know why. Also dumping { on a new line is bad because it introduces a place to break everything on insertion that won't cause a compile failure. 50% of the thread will now tell me I'm wrong.
|
# ¿ Mar 30, 2017 08:24 |
|
Zopotantor posted:This. And forget replacing them by singletons, too; those are just a way to get globals in languages that don't provide them natively. rjmccall posted:Global variables defined in the same translation unit should get initialized in the order they're defined. The rules get more complicated with static data members of class templates, and I wouldn't want to rely on compilers obeying those rules correctly, but the simple case of a bunch of non-template globals should be fine.
|
# ¿ Apr 8, 2017 08:25 |
|
High Protein posted:They keep 'improving' intellisense but last time I checked, even on rather small projects it was crap compared to VA. We use VA at work with a solution with ~200 projects and it works great. What I use most: Do you know if you can map those to other things in vsvim? Because all of those things I already have key bindings for in vim and I am incapable of relearning keybindings.
|
# ¿ May 19, 2017 19:06 |
|
Xarn posted:True, but that would probably lead to ton of idiots not realizing that struct has all the features. I had a cto of a tech startup tell me I was wrong about class and struct being basically the same after asking me for the differences in an interview. I had to pull out the standard to correct him. Didn't get the job.
|
# ¿ May 28, 2017 14:39 |
|
Love Stole the Day posted:Tell that to his bank account Yeah I was unemployed at the time; it sucked.
|
# ¿ May 28, 2017 14:49 |
|
roomforthetuna posted:I guess I should phrase this in the form of a question just in case it's me that's wrong and bad. Yeah, you got asked a maths question not a c++ question. Assuming he was talking about a collection of N numbers.
|
# ¿ May 29, 2017 11:21 |
|
sliderule posted:Getting back into C++ after 20 years is pretty refreshing. The STL and the language advancement in 11 to 17 are very nice. Sure, install clang and symlink clang++ to g++
|
# ¿ Jul 5, 2017 21:13 |
|
Ralith posted:Worrying about efficiency is one of the worst things you can do while you're learning. Arguably it's not that great beyond a cursory point after you're experienced, too. Until your tools tell you things are too slow anyway.
|
# ¿ Jul 23, 2017 00:06 |
|
Slash posted:This is how I do profiling, (attach debugger, randomly hit pause in the debugger and see where you are in the call stack), law of probability says you'll likely hit the offending method that's taking up all the time. Why not spend less time and get more information by opening a single window?
|
# ¿ Aug 4, 2017 12:42 |
|
underage at the vape shop posted:Is this the right place to ask questions about C# and visual studio? How in the gently caress do I get it to accept that I want to change namespace? I change it in properties, there doesn't appear to be a save button, and I go back to my code and it still says "namespace WindowsFormApp6". Changing the namespace is required to get the automarking system to accept it. The .net thread is probably better. Why can't you just change the name of the namespace in your code? It's plaintext..?
|
# ¿ Sep 14, 2017 14:29 |
|
Volguus posted:Debian, Fedora and CentOS don't have the same version, of course. So far we have found Debian to be the stable platform, but that's the problem, what if Debian, that version of gomp or omp, just so happens to not trigger existing bugs. Build your dependencies, OP, don’t just use whatever the system feels like shoving at you. There isn’t a good reason critical parts of your application have different versions on different platforms unless you made that an active choice.
|
# ¿ Apr 4, 2018 13:36 |
|
SuperKlaus posted:You guys have been a big help. Typically when I see the unexpected negative numbers it's because I've done something like forgetting to initialize the element of an array that I used in the calculation. Max size of data types is that sort of thing ya learn in CS 101 and then never see in practice in your courses so you forget. How embarrassing. I’ve run into type bound issues somewhat frequently so far in my career. One of those things you just start testing to make sure things behave reasonably at the edges.
|
# ¿ May 15, 2018 20:08 |
|
unidef freeman posted:I overheard this in IRC from the good programmers, is it possible to make a trinary tree? Sure; each node has three children.
|
# ¿ Jan 15, 2019 18:08 |
|
peepsalot posted:Anyone know a good tool that's not Java based to help find duplicate or unused code across a C/C++ project? http://clang-analyzer.llvm.org/scan-build.html ?
|
# ¿ Nov 9, 2019 18:12 |
|
Brownie posted:This is perhaps a dumb question, but whats the best way to throw an error with exceptions turned off? I'm writing code that in certain cases I want to fail completely (because it's only reachable due to programmer error) with a helpful debug message (in debug) and also still bomb in a Release build as well. Comedy option setjmp and longjmp
|
# ¿ Mar 13, 2020 22:39 |
|
|
# ¿ May 21, 2024 03:16 |
|
Elfforkusu posted:I had this happen! I don't even know if that sounds good or bad at this point.
|
# ¿ Apr 24, 2020 11:44 |