Anonymous
only created when provoked
Nils
https://hastebin.com/itiyusamam.cpp Hi, what is the reason for line 17 to segfault? I am getting no warning or error in compiler…
Nils
ohhh nvm I found it right after posting the question
Nils
I'm so stupid sometimes
Anonymous
why u using struct enums
Anonymous
??
Nils
Can I compare a std::string with a std::string_view, is that any problematic?
Nils
whats that
a string_view?
Anonymous
he purpose of any and all kinds of "string reference" and "array reference" proposals is to avoid copying data which is already owned somewhere else and of which only a non-mutating view is required. The string_view in question is one such proposal; there were earlier ones called string_ref and array_ref, too. The idea is always to store a pair of pointer-to-first-element and size of some existing data array or string. Such a view-handle class could be passed around cheaply by value and would offer cheap substringing operations (which can be implemented as simple pointer increments and size adjustments). Many uses of strings don't require actual owning of the strings, and the string in question will often already be owned by someone else. So there is a genuine potential for increasing the efficiency by avoiding unneeded copies (think of all the allocations and exceptions you can save). The original C strings were suffering from the problem that the null terminator was part of the string APIs, and so you couldn't easily create substrings without mutating the underlying string (a la strtok). In C++, this is easily solved by storing the length separately and wrapping the pointer and the size into one class. The one major obstacle and divergence from the C++ standard library philosophy that I can think of is that such "referential view" classes have completely different ownership semantics from the rest of the standard library. Basically, everything else in the standard library is unconditionally safe and correct (if it compiles, it's correct). With reference classes like this, that's no longer true. The correctness of your program depends on the ambient code that uses these classes. So that's harder to check and to teach.
Anonymous
he purpose of any and all kinds of "string reference" and "array reference" proposals is to avoid copying data which is already owned somewhere else and of which only a non-mutating view is required. The string_view in question is one such proposal; there were earlier ones called string_ref and array_ref, too. The idea is always to store a pair of pointer-to-first-element and size of some existing data array or string. Such a view-handle class could be passed around cheaply by value and would offer cheap substringing operations (which can be implemented as simple pointer increments and size adjustments). Many uses of strings don't require actual owning of the strings, and the string in question will often already be owned by someone else. So there is a genuine potential for increasing the efficiency by avoiding unneeded copies (think of all the allocations and exceptions you can save). The original C strings were suffering from the problem that the null terminator was part of the string APIs, and so you couldn't easily create substrings without mutating the underlying string (a la strtok). In C++, this is easily solved by storing the length separately and wrapping the pointer and the size into one class. The one major obstacle and divergence from the C++ standard library philosophy that I can think of is that such "referential view" classes have completely different ownership semantics from the rest of the standard library. Basically, everything else in the standard library is unconditionally safe and correct (if it compiles, it's correct). With reference classes like this, that's no longer true. The correctness of your program depends on the ambient code that uses these classes. So that's harder to check and to teach.
why did you copy this wall of text
Anonymous
why did you copy this wall of text
Beacuse I didnt want to type
Anonymous
https://www.educative.io/edpresso/what-is-the-cpp-string-view-in-cpp-17
Anonymous
Can I compare a std::string with a std::string_view, is that any problematic?
no,in string view we can only view string,works as const char
Anonymous
remain unchanged
Anonymous
Beacuse I didnt want to type
they knew what std::string_view is. their question was whether operator==(std::string_view &, std::string &) would work. obviously it will. the string will get converted to string_view
Anonymous
What is the purpose of struct enums union??
Anonymous
If we still have classes??
Nils
and debugability
Nils
In my experience enums are displayed correctly while that what you are talking about are not.
Nils
Can std::string be overflowed?
Francisco
What is the purpose of struct enums union??
Structs are different from classes in a conceptual way, but in practice, you can use both for the same purpose. Enums are just syntactic sugar for types you only want to have specific values (for example, a direction can only be up, right, down and left). Unions are completely different. They are meant for types whose attributes share the memory
Ariana
Can std::string be overflowed?
https://stackoverflow.com/questions/10398144/does-buffer-overflow-happen-in-c-strings generally from experience c++ pwning is significantly harder tho
Nils
I think I somehow managed to overflow it…
Nils
Just by pushing random data in
Nils
I notice the overflow because one of my bools has a value of 3 afterwards.
Nils
Just overflowing with \0 seems to not have that effect
Francisco
I think I somehow managed to overflow it…
"overflowing" a std::string seems quite weird, because the only way you can "overflow" it is by running out of memory
Nils
Wait, I can send the problematic code…
Nils
https://hastebin.com/nejonofohe.cpp can you see anything wrong?
Nils
I have no idea how else it overwrites wrong data
Aha, it's overwritten on disconnect
Anonymous
Who has a resource on how to learn C with Visual studio
Asdew
Who has a resource on how to learn C with Visual studio
The University of Helsinki and Aalto University have created a MOOC course together, I have not tried it, but I've heard the Java MOOC course by the University of Helsinki is excellent. https://moocfi.github.io/courses/2016/aalto-c/en/
#свободуНавальному
Hello. Why c compiller (gcc) compile it, but c++ (g++) no? I wanna use c files inside c++ without changes. It is possible? p.s. This example just show the problem, therefore don't suggest fix c code if it not critical warning in c and need only for work this in c++ "extern".
#свободуНавальному
#свободуНавальному
Dima
LMAO
Anonymous
I'm writing a while loop, that should show to the user some kind of menu, where the user can type his choice, or 'enter' to use the default option. In order to do so I'm using an fgets function, and I would like to clear the buffer after that, in order to not compromise the further selections. If I use something based on getchar() my program enter in some kind of loop and stops working right after the fgets Here is a sample of my code https://pad.riseup.net/p/-skZv-GPDMwV1oJAYUGU-tmp
Anonymous
Hi to everyone ;)
Nils
Can I enable optimisations and debug at the same time?
Anonymous
Can't say much. Code is not enough.
you're right, thanks for watching It. Here is the partial program that I wrote https://pad.riseup.net/p/ask-c-question-tmp
Anonymous
I'm a newbie and I'm learning C on my own, probably there are some coding horros 😂
Surya
Guys I am confused in reading these fat16 filesystem directory entries. The directory structure provided on internet is too direct to fit with this. Help.
Anonymous
the line I'm talking about is the number 70
Mandelbröt
Any way to concatenate a string k times (k<=10^18) Its giving tle ...(in c++)
Anonymous
Use gnu readline or any operating system specific extension
Surya
Use gnu readline or any operating system specific extension
The codes I see are too confusing. And I am searching for explanation for the whole root directory entry. Which I am not able to find.
Anonymous
Fgets only when you actually read from a file
Anonymous
thanks
Anonymous
[In reply to Cooooooooooom'); DROP TABLE ALL; GNU/Yuki Nagato జ్ఞాజ్ఞాజ్ఞాజ్ఞ (長門有希) XDA: @anupritaisno1 @glassrom I use Arch btw జ్ఞాజ్ఞాజ్ఞ] then, how can I write a program that behave, for example, like fdisk? It shows to you the default option, but lets you to use a custom one. I'd like to do that
Anonymous
I know what it is just thinking about it
Anonymous
It's just an example, I'm talking about the gnu utility that manages partitions
Anonymous
parsing arguments isn't hard
Anonymous
even for beginners
Anonymous
the actual work of fdisk might not be for beginners
Anonymous
I think It's too hard for me.. it doesn't matter, I'll find a solution in the future when I'll be more experienced. Anyway I obtained what I expected, the problem is that sometimes, the second choicebis being altered by the buffer. Sorry for my bad English
Anonymous
Std::vector<int> snail(std::vector<std::vector<int>> snail_map) { //code or no code shows the same thing } Int main() { Snail({{1, 2, 3}, {4, 5, 6}}): } This is showing "Double free or corruption (out)" Why? And how to solve thus
Anonymous
Wut the problem its a vector inside a vector
Anonymous
No its the part of a question
Anonymous
I didnt write any if my code and its showing me the error
#свободуНавальному
Hello. Why c compiller (gcc) compile it, but c++ (g++) no? I wanna use c files inside c++ without changes. It is possible? p.s. This example just show the problem, therefore don't suggest fix c code if it not critical warning in c and need only for work this in c++ "extern".
#свободуНавальному
Gcc works with only c and g++ only works with c++
I wanna use c code inside c++ code. And i extern it and compile cpp file
Anonymous
Why do u wana use c code inside c++?
#свободуНавальному
For split libs on c and c++ I should use c libs inside c++
Anonymous
Hello
Anonymous
How to reboot android with c program.
Anonymous
I use c4droid.
Anonymous
I'm writing a while loop, that should show to the user some kind of menu, where the user can type his choice, or 'enter' to use the default option. In order to do so I'm using an fgets function, and I would like to clear the buffer after that, in order to not compromise the further selections. If I use something based on getchar() my program enter in some kind of loop and stops working right after the fgets Here is a sample of my code https://pad.riseup.net/p/-skZv-GPDMwV1oJAYUGU-tmp
anyway I've found a solution based on this question https://stackoverflow.com/questions/45469868/clear-input-stream-after-fgets-set-null-char-before-newline. So basically I use 'while( !(getchar() != '\n' ));' after the fgets function, only if the lenght of the string used by fgests is >= of its (max - 1) lenght and if its last charachter is different from a newline
Surya
Anyone can help with filesystem?
Anonymous
Does someone have a tool for windows which shows the hirarcy of h files?