« first day (165 days earlier)      last day (2684 days later) » 

12:41 AM
Hello, i have a short question. I am programming on my mac and installed the newest version of the gnu compiler gcc 6.2.0. Im using xcode and coded this short part:
string full_path;
	DIR *dir;
	struct dirent *ent;

	if ((dir = opendir (dir_target.c_str())) != NULL)
	{
		while((ent = readdir (dir)) != NULL)
		{
			if(strstr(ent->d_name, ".txt") && !strstr(ent->d_name, "Summary"))
			{
				full_path = dir_target;
				full_path = full_path + ent->d_name;
				list_in.push_back(full_path);
			}
		}
		closedir(dir);
	}
	else
	{
		printf("could not open directory");
		perror ("");
	}
xcode compiles this code without a problem but when i try to compile and run it from the temrinal it gives me the error that "strstr" wasnt defined in this code part
 
nwp
12:57 AM
@Schbabako did you #include <cstring>?
 
 
2 hours later…
3:17 AM
no i did not. But why does it work in xcode then?
 
 
6 hours later…
9:31 AM
2
A: Does the standard specify what headers include other headers?

hvdThe general rule about which headers may be included by other headers is: there are a few headers that are specified to be included automatically, and other than that, it depends on the implementation and does not need to be documented. 17.6.5.1 Conforming implementations [conforming] 17...

 
 
1 hour later…
10:55 AM
Can I get some help with MinGW and CLion IDE. Got some problems with missing DLLs.
 
> not using MSYS2
 
No, I have MSYS in my MinGW installation folder, and please keep it simple I am new to this stuff
 
Is it MSYS2 or just MSYS, because this is a world of a difference
(also thanks to the efforts of everyone, I can never be sure if by MinGW you mean the ancient mingw.org builds, TDM ones, MinGW-w64, or the one provided by MSYS2)
I can recommend MinGW-w64 or MSYS2
@FrostyTosty don't worry, sometimes I get confused too and I'm doing this waaaaay too long
 
11:35 AM
it is MSYS
 
12:02 PM
@FrostyTosty What does g++ --version print?
 
12:26 PM
If you meant type it in CMD: I get the usual not recognized msg. 'g++' is not recognized as an internal or external command,
operable program or batch file.
I figured it out, beginner's mistake, didn't have the %path% to mingw\bin set. But does this mean every user needs to have those DLLs installed to use my program? How can I ship it out to a user without them needing the extra DLLs, just the .exe?
 
12:42 PM
@FrostyTosty you could use static linking of libstdc++, but then again delivering dlls isn't usually a problem - a typical program needs to deliver assets along (for example, sound effects, sprites or models for games), so extra files aren't usually a problem.
 
Any ideas on how do I link it in CLion, since it uses CMake and has no compiler flags like Eclipse I am a bit confused.
 
 
3 hours later…
3:39 PM
Hi, i'm using codeblocks and trying out SDL 2.0. I first call the SDL_Init function and then create a window. The program runs, but the window appears for a split second then disappears what could be the problem
on windows
 
SSCCE please
 
nvm got it
 
4:28 PM
Hello, does anyone there have experience with proper, idiomatic use of C++'s exceptions?
 
4:41 PM
Who doesn't
Out of context: you might be compiling on windows and to a console project. You migh be seeing the console window, and forgetting to create an SDL window
 
Well, I don't, that's why I'm here xD

I want to show code snippet with my question. You would prefer to see it on some external site, like pastebin, am I right?
 
5:29 PM
@Toreno96 post it on ideone or coliru
 
5:44 PM
This may be a stupid question but
Why does that give me 8 for the sizeof(arr); .. isnt is suppose to give me 20 , since 5 (element num) * 4(4 bytes for integer atleast in x86 & x64 systems)
 
nwp
@Dsafds arr is not an array, it is a int *
one of the reasons why C++ prefers std::array and std::vector
 
6:00 PM
@nwp yeah isnt an integer 4 bytes?
I was expecting 4 or 20..
How come 8?
 
nwp
@Dsafds you are not checking the size of an integer, you are checking the size of a pointer, which on a 64 bit system happens to be 8 bytes
 
@milleniumbug I don't think coliru was a good idea, because I'm giving a code snippet that cannot be compiled when being only a snippet. But you're the doc, doc!

http://coliru.stacked-crooked.com/a/07cea0212a228ff6

While every other exception is handled by the try-catch that is present in System::run, I don't know where should I handle exceptions thrown by function called by Shell::runCommand, and where I should handle exception thrown by Shell:runCommand itself. Should I make another try-catch, this one in the while-loop in System::run, having only call to Shell:runCommand inside it's tr
 
@Dsafds Instead of pondering the insanity of this particular result, follow a simple rule of thumb: never use new []. For every case where you might consider using it, there's at least one alternative that's superior (and often a couple of them).
@Toreno96 There are two fundamental questions to answer here. One is: at what level does the code really know how to handle the exception in each case? The other is, do the exceptions need to be handled differently?
 
6:22 PM
@JerryCoffin
1. At the level of Shell::runCommand. I forgot to mention that handling these specific exceptions will be just displaying error message (e.g. "Invalid command name") to the user, sorry ^^'
2. I think not, because by "displaying error message" I mean "displaying what_arg".
 
My immediate reaction would be something like this. That is, some exceptions do have to be handled differently from others. In particular, a bad command just results in an error message, but continued execution, but other exceptions internal to the shell, probably result in that shell exiting.
The big question there would be whether a bad command really qualifies as an exception at all. Bad input is common enough that it's hard to really claim it's exceptional or unusual.
 
6:39 PM
I know that some exceptions do have to be handled differently from others, that's why I have separate try-catch for crashing a whole system and separate one near or inside the Shell::runCommand function (for now not present in the code yet, because of my dilemma).
About the "big question" - then how should I handle bad input, instead of using exceptions?

it's not that I'm using one-word commands. I'm calling a function, based on inputted command's name, giving it inputted arguments. I need to check if name is valid, then I need to check is count of arguments for specific function is valid (inside this function) and finally, are arguments itself are valid (again, inside this function).

I thought exceptions are perfect for such task.
Of course, I could write an error message in function called by Shell::runCommand, it has access to iostream library, but wouldn't that be just plain wrong, @JerryCoffin? ;)
 
@Toreno96 Yes, it's probably wrong for it to directly print out the error message. There's some room for it to (for example) return an optional<command> that will just be empty if the input couldn't be parsed.
 
7:03 PM
@JerryCoffin But Command's ctor isn't checking if input was valid command, Shell::runCommand does it ^^'

The only think Command does is parsing line of text to separate potential command name and it's arguments.

Shell::runCommand is calling adequate function based on it's name. I have std::map with the name as key and the function (accepting std::vector of arguments) as value. If the name is not present in this std::map, exception is thrown. If it is present, then the right function is called.
 
@Toreno96 I'd tend to say that's not the best design. In most typical cases, the ctor should check its inputs, so once an object is created, it can do what it's supposed to. In fairness, however, there is some possibility of a race condition, where something was valid when you read the command, but (for example) a file gets deleted, so a millisecond later when you try to execute it, that command is no longer valid.
 
@JerryCoffin But as I said, Command class is supposed only to parse input, so Shell::runCommand wouldn't need to do this. I could name it shellInputParser and it wouldn't change anything (maybe besides readibility, maybe it's a good idea after all?).
No, after a while, I'm not so sure it would increase readibility.
AFK, for a moment.
 
7:45 PM
I'm back.
 
8:34 PM
guys do i have to resize here ? buffer std::vector
 
buffer is another vector, yes?
 
yea
buffer = vector p.buffer = vector
 
you don't need to explicitly call resize, and you might want to just make buffersize a function that calls buffer.size()
 
ah okay
tnx
 
behavior of operator= for vectors is as described here
 
8:39 PM
tnx
 
cppreference is a good resource that describes c++ behavior in a human-readable way, and it's rarely inaccurate (and then only in extremely pedantic ways). You might want to bookmark it.
 
If I have definitions in header file (from colleague : /) and include it in multiple source files, there will be linker errors, right?
 
If I have a header file and an implementation file, it's okay declaring some functions in the implementation (.cpp) file, right?
If those are just "implementation detail"
And I don't feel I'll be able to reuse them anywhere.
 
3 messages moved from Lounge<C++>
 
yes, in practice that works, though you should be sticking them in an anonymous namespace to be technically correct and not violate ODR
 
8:50 PM
Well, the reason why I don't put them in the header is because they're irrelevant to the person reading the header
Oh, I'm putting the anonymous namespace so that the function couldn't be use anywhere else, outside the implementation file?
If someone just so happens to declare it?
 
you're putting them in the anonymous namespace so they have a different name than any other implementation function in a different cpp file
 
Okay, thanks
Aha
 

« first day (165 days earlier)      last day (2684 days later) »