Vlad
It just hinders your ability to do arithmetic
ببب ب
Unless youre talking about explicitly converting to void* when constructing through the placement new
Anonymous
LOL
Vlad
Imo void* pointer is useless if char* exists
Like the only reason I see fit is that you wouldn't want to cast it to a string implicitly like char* does
Anonymous
wouldn't arguably byte* be better for it that? since then any size is actually usable on the arithmetic of the returned pointer
Yes it would be but it was introduced as a library type in C++17 and byte is intended to be used for bitwise operations. You won't be doing bitwise operations on raw memory and hence this does not fit the use case I am talking about. The point I was trying to make is that void* pointer allows you to treat memory as a collection of raw bytes. You shouldn't ideally be doing pointer arithmetic when this is the case and void* fits this use case. Allocator_traits is a facade layer and shields users away from the nitty gritty of the actual allocations. So it presents a pointer to the value_type. As an example, look at Hans Boehm's garbage collector reference implementation for C++. You would find well defined uses for void* pointer there where hazard pointers are used.
Anonymous
Can someone help me?
coal
damn everything i wanted to say is already mentioned in the following replies i feel sad now
Anonymous
Hey guys, can anyone help me with getting conio.h to work in my code
İlkay
hey guys, ı need help
İlkay
ı have three dimensional array homework
coal
ı have three dimensional array homework
wow sounds like you got some homework to do!
coal
by yourself!
coal
unless you have a specific question and if that's the case you can ask here and we'll gladly help you
Anonymous
Is there any specifier in C that accepts values of hex, binary, decimal input values? 😂😂😂
coal
yeah strings
Anonymous
Like I am building a scientific calculator
coal
ohhh
coal
you can scan hex and octals using %i
Anonymous
Calci needs to provide for hex and binary number input and output in addition to decimal input & output.
İlkay
ı will write code enroll course and ı have to campus [2],course[3], year[4] but ı dont know how to begin ?
Anonymous
Now I am successfully running for integers
coal
Calci needs to provide for hex and binary number input and output in addition to decimal input & output.
int myhex; scanf("%i", &myhex); // input: 0x12345 printf("%d", myhex); // 74565
coal
and for outputting in hex use %x
Lucas
If I want to build nested data structures with classes. I'm getting a free Double at tcache2 error what could It be
coal
int myhex; scanf("%i", &myhex); // input: 0x12345 printf("%x", myhex); // 0x12345
coal
If I want to build nested data structures with classes. I'm getting a free Double at tcache2 error what could It be
your problem doesnt have relation with the nesting, hard to tell without knowing your code
coal
you're welcome
coal
Thanks a lot ...gonna try now 🙏
wait, just checked again and %i doesn't take hex
coal
use %x instead, my bad
coal
int myhex; scanf("%x", &myhex); // input: 0x12345 printf("%x", myhex); // 0x12345
Anonymous
Ok sure, thanks again 💐
mhr
Please any help I want to learning C++ I’m a beginner 🙂
Anonymous
Hey friends, who would like to explain to me what is the purpose of adding term "temporary materialization conversation" in cpp17? After reading the reference page of cppreference, I got more confused about it😕.
Anonymous
https://en.cppreference.com/w/cpp/language/implicit_conversion
Pavel
Hey friends, who would like to explain to me what is the purpose of adding term "temporary materialization conversation" in cpp17? After reading the reference page of cppreference, I got more confused about it😕.
As far as I understand that's a part of standardizing already existing optimizations and make them required, so if I get it correctly some already existing rules of the language were described in different terms so the new ones fit into them nicely. But I'm not an expert on this topic, it's just how I understood it.
Anonymous
Hey friends, who would like to explain to me what is the purpose of adding term "temporary materialization conversation" in cpp17? After reading the reference page of cppreference, I got more confused about it😕.
You can think of temporary materialization as a way of not creating temporaries unnecessarily. Suppose you have a chain of calls where the first call creates a temporary and that temporary is passed through the chain of calls then this temporary creation happens at the last stage and all the intermediate stages skip that temporary initialization. It is like lazy evaluation (almost). So if your function returns a non copyable or a non movable type then this feature lets you do so. Another way to think of it is guaranteed copy elision where previously copy elision was a compiler optimization.
Denis
//the text is given. write a program to cyclically shift all lines of the input text to the right by eight positions int main() { FILE* bb, * aa; int n, i, j; char str[1000], c; fopen_s(&bb, "text1.txt", "w"); fopen_s(&aa, "text.txt", "r"); printf("Vvedite kolichestvo simvolov\n"); scanf_s("%d", &n); c = fgetc(aa); i = 0; while (c != EOF) { str[i] = c; i++; c = fgetc(aa); } char t = str[0], x; for (int i = 0; i < 8; i++) { str[0] = str[i-1]; for (int j = 1; j < 8; j++) { x = str[j]; str[j] = t; t = x; } fputc(str[i], bb); } fclose(bb); fclose(aa); }
Denis
help pls
Max
Who knows how to sort array with pointers on structs using qsort?
Max
int compare(const void *pa, const void *pb){ const data_t *p1 = pa; const data_t *p2 = pb; return strcmp(p1->group , p2->group); //const data_t *p1 = pa; //const data_t *p2 = pb; //int cmp = strcmp(p1->group , p2->group); //if(cmp != 0) // return cmp; } qsort(array,10,sizeof(data_t),compare); Something like that maybe but it doesnt works
پویا رحیم
Hi. Question : Why does std::string_view::find return std::string_view::npos if it doesn't find a substring? str.find("substring here") will return std::string_view::npos if it doesn't find "substring here" in str. Why doesn't it return boolean true or false instead? We use this as our condition: (str.find("nut") != std::string_view::npos); When it would be much simpler to use: !str.find("nut") And I don't see what reason there is for this to happen, so thought I'd ask you guys for some insight here.
artemetra 🇺🇦
Hi. Question : Why does std::string_view::find return std::string_view::npos if it doesn't find a substring? str.find("substring here") will return std::string_view::npos if it doesn't find "substring here" in str. Why doesn't it return boolean true or false instead? We use this as our condition: (str.find("nut") != std::string_view::npos); When it would be much simpler to use: !str.find("nut") And I don't see what reason there is for this to happen, so thought I'd ask you guys for some insight here.
This is a special value equal to the maximum value representable by the type size_type. The exact meaning depends on context, but it is generally used either as end of view indicator by the functions that expect a view index or as the error indicator by the functions that return a view index. https://en.cppreference.com/w/cpp/string/basic_string_view/npos there's code there that creates a constexpr bool contains function that would do exactly what you want
artemetra 🇺🇦
hope it cleared that up
پویا رحیم
hope it cleared that up
Yep! Thanks a lot 🙏
ببب ب
why would char be signed?
ببب ب
doesn't make much sense to me
ببب ب
why would char be signed?
@SilhouetteInDark mabye you can explain? 🤔
Rio
No prblm bro 🙏🏻
h
how to put sort technique in search technique code? i already have the code but idk how to insert sort tech in my code...can someone explain to meeee
Rajesh
Have a doubt anyone help me I need to load the json details to database I did it in java but now I need to do it in jni so should I import json,sql classes in jni c++ itself and store to database or I should just parse the json in c++ and return it to the java
Rajesh
Please help me im fresher
Samir
Hello friends, I am a beginner in c++ can you tell me how to make a text appear Letter by Letter using c++
Samir
Or a word appear letter by Letter E.g. Foodie => I want it to appear like f first then o then o following d following I following e
ببب ب
Perhaps this is a foolish question but is there a reason why the three catch branches here can't be coalesced? void bar() { try { foo(); } catch(foo_exception&) { baz(); } catch(std::out_of_range&) { baz(); } catch(...) { baz(); } } https://godbolt.org/z/nnP9jYc4b and I've another question which is almost certainly foolish. If I have a custom exception like foo_exception above and I know it will only ever be thrown in one place, but I disable it being thrown for e.g. in a release build, is there a way to indicate that all exception handlers for foo_exception can be omitted? I figure the answer is almost certainly no. Not that it matters for anything other than binary size but I've a niche use for something like this
ببب ب
No
ببب ب
that was my question
Samir
Ok good luck brother
ببب ب
How do compilers keep track of RTTI when it comes to primitive types? As in I've somewhat understood how RTTI works in general with virtual but I found very little when it gets to int & co
Samir
Clue : string is array of char
Could not get ya friend. May you explain in further
Anonymous
why would char be signed?
This is because of backwards compatibility reasons with C. C doesn't have a type to represent characters. The name is a misnomer. char as was originally planned out by Kernighan and Richie was an integral type which is the smallest on that architecture. That explains why it can be both signed and unsigned like any other types. Characters are represented by their integer codes which is why the name char seemed reasonable at that time. The requirement for this type was that it be large enough to hold the basic character set of that machine and was defined to be of size 1 byte (a byte here does not necessarily mean 8 bits). Now there is this additional question of why a char is allowed to be either signed or unsigned depending on the actual implementation. This is because processors and their Instruction Set Architecture favor a specific type of char because it fits nicely onto the machine instructions in place. For example the System V ABI defines char to be a signed char. A char being signed or unsigned affects calling conventions because of the requirement that narrow types are sign or zero extended. So plain char had to be defined explicitly to map to one of those types based on the underlying architecture as compared to a plain int which is just another way of saying signed int.
Anonymous
when you say a byte doesnt necessarily mean 8 bits, what does that actually mean
There were architectures in use when the first C standard was adopted which were 9 bits wide (PDP 11). On these architectures sizeof(char) would still return 1 but the size of a byte on these machines would be 9 bits wide. You won't find such arcane architectures today
coal
i see
coal
so i assume the C compiler also dealt with these architectures along as for the common 8 bits per byte
Hsn
Oki...in cpp push_back is there
Is it ( stack ) data structure problem .. ?
coal
i can only guess C wasn't very usable in these architectures due to the alignment
coal
wish i had one of these to test
Anonymous
i can only guess C wasn't very usable in these architectures due to the alignment
Anything that was 9 bit wide would be aligned on such architectures as would be 18 and 36 bits
coal
what about the opcodes though
Anonymous
what about the opcodes though
If an architecture were 9 bit wide, the opcodes and registers would all be 9 bit aligned.