Francisco
Emir
Francisco
It warns you that using variable length arrays is actually forbidden by the ISO C++
Francisco
G++ lets you use vla, but that doesn't mean it's actually allowed
Emir
Emir
Emir
Francisco
C/C++ compilers are quite permissive in what you can compile and what not. They may allow code that is not 100% conformant with the standard, just to allow backwards compatibility
Francisco
Like for example variable length arrays. You shouldn't use them because the stack may blow-up, but as it is allowed in C, they just let users use them in C++ code
Francisco
Other examples may be that you're compiling some code in C++14 using some C++20 feature. The compiler might (and most likely will) warn you that the feature is available in C++20 mode and not C++14, but it might still let you compile that code
Emir
Okay, what compiler are u using?
Francisco
I mainly use gcc and clang, and the last version if possible
I_Interface
Francisco
I don't use Windows, so no point in using MSVC
Francisco
Ubuntu 16.04, but planning to upgrade to Ubuntu 20.04 as soon as I'm finished with college
I_Interface
use debugger and watch it step by step
Anonymous
Anonymous
Hai
Anonymous
Hi, I'm trying to get a solution I wrote to a SPOJ problem accepted. I've tried to submit it more than once, but I keep getting this runtime error called 'SIGABRT', I don't really understand why
Anonymous
Here's the code: https://pastebin.com/PN7Mk79H
Anonymous
This is the problem: https://www.spoj.com/problems/ACODE/
Anonymous
Could any of you take a look at it to see if I'm missing some silly thing?
Anonymous
I'm kinda new to competitive programming, so any help would be appreciated
Anonymous
Okay, I replaced the dynamically allocated array with a vector; now the error is gone but I'm getting wrong answer lol
Anonymous
Nevermind, got it
MᏫᎻᎯᎷᎷᎬᎠ
Can't we have a feature like variable whose values are known at compile time? Keyword is constvar
Like this:
constvar int cv = 1;
cv = 2;//known by the compiler
int v = 0;
cv = v;//Error, must assign with a constant expression
MᏫᎻᎯᎷᎷᎬᎠ
Well the idea came when I was thinking about the ownership model in Rust and how the change of state in Object is detected by the compiler and known
MᏫᎻᎯᎷᎷᎬᎠ
Imagine state is changed and detected at compile time
That would be great, and may prevent a lot of errors
MᏫᎻᎯᎷᎷᎬᎠ
That means creating a new variable
MᏫᎻᎯᎷᎷᎬᎠ
And it may be some kinda costy
MᏫᎻᎯᎷᎷᎬᎠ
Come on
The valid state of the move constructor could be know at compile time
MᏫᎻᎯᎷᎷᎬᎠ
That's pretty cool
Anonymous
Employee record project ?
MᏫᎻᎯᎷᎷᎬᎠ
Noo
constvar object are only allowed to call constexpr methods
noop
Here's the code: https://pastebin.com/PN7Mk79H
- Do you need cstring library?
- Make result a local variable, initialize it with NULL (nullptr), pass it to other functions as an argument, check if it can allocate memory, check if has been allocating memory before deleting it.
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
Why not
constvar int var = 0;
DoSomeCompileTimeCalculationBasedOSomenInputs(var,....);
isPrime<var>::
.
.
MᏫᎻᎯᎷᎷᎬᎠ
Changing a constvar variable inside the object
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
So
It's cool, right? :D
Anonymous
Thanks, I realized these. I changed the array part and tweaked the logic a bit, then got it accepted
Anonymous
But the code is ugly lol
Anonymous
Need to practice so much more
Anonymous
It still is. First DP code I ever wrote
Anonymous
This was very hard, but fun
MᏫᎻᎯᎷᎷᎬᎠ
The compiler has to track only the constexpr calls or consteval methods
It's easy then since ordinary variables are not allowed in such context :)
MᏫᎻᎯᎷᎷᎬᎠ
Oh
It's night there
I just woke up lol
MᏫᎻᎯᎷᎷᎬᎠ
there is a library for that
But I don't recall its name
MᏫᎻᎯᎷᎷᎬᎠ
I don't get it
Do you mean what is the case when constexpr methods are not compile-time guaranteed?!
Then consteval then
Nils
Hi, I am tryinto to read input from gamepad, wait until A is pressed:
while (!((u32)hidKeysDown() & KEY_A));
What's wrong here? It won't unpause even if I press A
Đỗ
may be u should check for value KEY_A equal to LOWWORD or HIGHWORD of the return value
Nils
Anonymous
I am trying to assign a const pointer to another pointer I know that it is forbidden, but I tried to avoid it overriding the operator=. Why it is forbbiden too? I dont find the logic.
Anonymous
Anonymous
I am obligate to use const_cast :-(
Anonymous
The incorrect line should be Figure* test2 = piece;
Anonymous
I will use the const_cast then. I wanted to confirm that was impossible to overload the assignment to a pointer and know the reason. Now, I can continue in a happy way!!
BIGMAC_1
Anyone here knows javascript?
BIGMAC_1
If yes pls tell me
Shvmtz
What is the difference between getc() and fgetc() ?
Dima
bruh.
Siddhant
Shvmtz
Shvmtz
"The difference between getc and fgetc is that getc can be implemented as a macro, whereas fgetc cannot be implemented as a macro"
- what does this mean ?
Dima
Anonymous
Bad practice
Dima
it is a bad practice
Emir
https://www.youtube.com/watch?v=4NYC-VU-svE
Dima
lol
Anonymous
You did not even watch the video
Emir
Emir
so what’s problem?
Anonymous
Watch again
Francisco
https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
Emir
i told u that the reason of your question in Turkish