Nils
In case?
It depends on compiler behavior.
Nils
With some compilers it might break
Nils
Pavel
SetPf
serial protocol parsing
Nils
It simply is not defined by the standard
Nils
Means undefined behavior
Pavel
It is
Well in this case I agree
Nils
Vlad
Vlad
Especially that delete is nasty
Vlad
If you want to type pun use memcpy
Vlad
You won't die by copying 4 bytes over. But your code will be free of ub
Nils
Nils
Lol
Vlad
No, just cast
I guess in this case he can just reinterpret cast. Cause all members are uint
Nils
Yeah
Nils
Ohhhh so that's what static_cast is for?? Changing signednes? 🤯
Vlad
Yeah
But you can't do that in general case
Vlad
SetPf
is this is right?
struct Value {
private:
size_t arr_size = 0;
uint8_t array[sizeof(size_t)];
public:
void PushByte(uint8_t i)
{
array[arr_size++]=i;
}
uint32_t asuint(void)
{
return *reinterpret_cast<uint32_t>(array);
}
int16_t asint16(void)
{
return *reinterpret_cast<int16_t>(array);
}
}
Vlad
Vlad
struct Value {
private:
uint8_t data[sizeof(size_t)];
public:
uint8_t& operator[](size_t i) { return data[i]; }
}
Vlad
Vlad
I mean why the size of size_t
SetPf
Vlad
SetPf
Nils
Nils
SetPf
Pavel
Nils
Explain pls. About const.
Const means the function won't change any class member so const functions are still callable for const instances
Nils
Why inline?
Performance, compiler will optimise away pointer if possible.
Anonymous
Pavel
Pavel
Member functions are
Anonymous
Nils
Sam
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
char ch;
char s[100];
char sen[100];
printf("\nEnter char");
scanf("%c",&ch);
printf("Enter word");
scanf("%s",&s);
printf("Enter sentence\n");
fgets(sen,sizeof(sen), stdin);
printf("%c\n",ch);
printf("%s\n",s);
puts(sen);
return 0;
}
Sam
Why isn't the fgets function working
Sam
Pls help
Al
fgets (sen, strlen(sen)+1,stdin)
Nils
Al
sam question sorry
Sam
Sam
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
char ch;
char s[1000];
char m[1000];
scanf("%ch\n",&ch);
scanf("%s\n",&s);
fgets(m,sizeof(m), stdin);
printf("%c\n",ch);
printf("%s\n",s);
puts(m);
return 0;
}
Sam
Over here it's working fine
Al
what is the error?
Al
try gdb?
Sam
I tried it
Sam
Can you pls try it once...and send the correct code if possible
Sam
I tried it many times
Al
yes but im in the car and using only phone atm 😄
Sam
Ohh okay...will you pls send it later
Al
ok ok
Sam
Thanks :)
Al
no
Al
np
Al
@sam_1208 you need to fflush(stdin) before fgets
Al
you scanf mess it up stdin
Al
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
char ch;
char s[100];
char sen[100];
printf("\nEnter char");
scanf("%c",&ch);
printf("Enter word\n");
scanf("%s",s);
printf("Enter sentence\n");
fflush(stdin);
fgets(sen,sizeof(sen), stdin);
printf("%c\n",ch);
printf("%s\n",s);
puts(sen);
return 0;
}
Al
(done in the car via remote terminal)
Al
😂
Al
dont drink and drive
Beyond
wtf
Al
im just a passanger anyway
baydo
UML???