What are you working on, Sup Forums?
Old thread:
What are you working on, Sup Forums?
Old thread:
Other urls found in this thread:
website.com
website.com
twitter.com
Please post an anime image next time.
operator overloading is good
PowerShell and .Net are the future
Overloading is never good. Operators should be multimethods.
where's the fucking trap anime image OP?
saged
Is anybody here transitioning?
How to make images with different contrast/brightness more "similar" to each other?
From what to what?
I'm trainspotting.
What's the go-to language for programming on Linux?
Male to female
Trying to add .save, .write methods and override __repr__ for a class that inherits from list. I found some cornercases with adding and multiplying, where it returned an instance of list and not an instance of itself. Are these all or are there more cornercases?
class Framelist(list):
"""Framelist class. Extends list by being capable of saving itself."""
def __add__(self, other):
"""Override self + other to return a Framelist, not a list."""
return Framelist(super().__add__(other))
def __radd__(self, other):
"""Override other + self to return a Framelist, not a list."""
return Framelist(other) + self
def __mul__(self, number):
"""Overrides self * number to return a Framelist, not a list."""
return Framelist(super().__mul__(number))
def save(self, path):
"""Saves self into a file at specified path."""
with open(path, "w") as file:
self.write(self, file)
def write(self, stream):
"""Writes itself to specified stream."""
stream.write(str(self))
def __repr__(self):
"""Returns string representation fit for saving."""
return "\n".join([str(len(self))] + [str(frame) for frame in self])
C++ to Rust
Programming what?
C#
>Male to female
Why would anyone want to downgrade?
>C++ to Rust
Why would anyone want to downgrade?
this
Making a new operating system for embedded devices.
Why not contribute to an existing one instead?
does it have a logo yet
Do you have recommendations for learning embedded c?
I've seen people click on a word in visual studio, have it highlight every instance of that word then when they edited the word it edited every instance.
How do I do that?
Please post your code of conduct, I need to know if I'm safe to expose myself by contributing.
How is embedded C different from regular C? You just learn C and then learn API for whatever platform you're using.
No niggers and spics allowed.
No niggers or tranneis allowed.
t. spic
CTRL + R
Get out, tranny.
> (You)
>Why not contribute to an existing one instead?
Proprietary and confidential restrictions.
install vim
:set hlsearch
/
Why is this not allowed?
/*Write a program that asks the user to enter the number of pancakes eaten for
breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Modify the program so that it outputs a list in order of number of pancakes
eaten of all 10 people.*/
#include
#include
#include
#include
using namespace std;
struct entry {
public:
string name;
int pancakesEaten;
entry(string& givenName, int givenPancakes)
: name(givenName), pancakesEaten(givenPancakes) {}
};
entry getEntry() {
string personName;
int pancakesEaten;
cout
>C++ to Rust
>Downgrade
Is it really reasonable to write your own proprietary embedded OS nowadays? There're dozens FOSS ones out there ready to be used, some of them aren't GPL.
it should be
def get_events(event):
# pass this var outside of this
var = event
raise EventLoopStop
def event_wait():
event_callback_set(get_events)
event_listen()
while True:
event_wait()
What's the best way to use "var" from get_events() in the global scope?
I have used a list in the global scope to which I append things from inside get_events(). I can also use global var inside of get_events(), but in my beginner programming books it said that using global variables in functions is bad. Like this:
Global variable solution:
def get_events(event):
global var
var = event
raise EventLoopStop
def event_wait():
event_callback_set(get_events)
event_listen()
while True:
event_wait()
List solution:
def get_events(event):
my_list.append(event)
raise EventLoopStop
def event_wait():
event_callback_set(get_events)
event_listen()
while True:
my_list = []
event_wait()
Is there a definitive way to handle this?
wait, maybe because there isn't a default constructor?
>40s to post
But it isn't
> (You)
>Is it really reasonable to write your own proprietary embedded OS nowadays? There're dozens FOSS ones out there ready to be used, some of them aren't GPL.
I get paid more and get to have fun writing it.
Plus I get paid to maintain it.
Yes, it compiles fine when you add one.
Why should it be allowed?
This is what you want
array entries(10);
>entry(string& givenName, int givenPancakes)
> : name(givenName), pancakesEaten(givenPancakes) {}
How do people typically examine and parse files never parsed before? Say no one's ever seen an MP3 before and it's used for some little program. Would you use a hex editor to discover the lastingSorry 128 bytes are ID3 info? Now that you have that information, how do you usually go manipulating it with no prior documentation.
No
Not a default constructor, i.e.
entry()
...
>PowerShell and .Net are the future
>calling anything microsoft the future
yikes, do you program professionally?
You usually check if it's plaintext first, if it is then it's probably not hard to understand.
If not then well, check the internet if there's a doc or something.
If all fails scoop around with hex editor and try to match known values. It's hard and mostly throwing shit at a wall and seeing what sticks.
GCC really should work on the error messages, compare
: In function 'int main()':
26 : :26:20: error: use of deleted function 'std::array::array()'
array entries; // not allowed
^~~~~~~
In file included from :4:0:
/opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/array:94:12: note: 'std::array::array()' is implicitly deleted because the default definition would be ill-formed:
struct array
^~~~~
/opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/array:94:12: error: no matching function for call to 'entry::entry()'
11 : :11:3: note: candidate: entry::entry(std::__cxx11::string&, int)
entry(string& givenName, int givenPancakes)
^~~~~
11 : :11:3: note: candidate expects 2 arguments, 0 provided
7 : :7:8: note: candidate: entry::entry(const entry&)
struct entry {
^~~~~
7 : :7:8: note: candidate expects 1 argument, 0 provided
7 : :7:8: note: candidate: entry::entry(entry&&)
7 : :7:8: note: candidate expects 1 argument, 0 provided
Compiler exited with result code 1
with clang's
26 : :26:20: error: call to implicitly-deleted default constructor of 'array'
array entries; // not allowed
^
/opt/compiler-explorer/gcc-7.1.0/lib/gcc/x86_64-linux-gnu/7.1.0/../../../../include/c++/7.1.0/array:110:56: note: default constructor of 'array' is implicitly deleted because field '_M_elems' has no default constructor
typename _AT_Type::_Type _M_elems;
^
1 error generated.
Compiler exited with result code 1
>Not a default constructor, i.e.
>entry()
Not entirely sure how am I suppoed to make it work.
Well you can't anyway because it uses a T&.
entry() {} in your class shuld work fine.
std::string name = "";
int pancakesEaten = 0;
entry() = default;
Find a proprietary program operating on such files and reverse engineer. Analyze the binary code. Introduce tiny changes in files and observe how the program reacts. It's a tedious process.
>Not entirely sure how am I suppoed to make it work.
All members are non-const and public.....
But I want to make that default constructor inaccessible. In fact,
/*Write a program that asks the user to enter the number of pancakes eaten for
breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Modify the program so that it outputs a list in order of number of pancakes
eaten of all 10 people.*/
#include
#include
#include
#include
using namespace std;
struct entry {
public:
string name;
int pancakesEaten;
entry(string& givenName, int givenPancakes)
: name(givenName), pancakesEaten(givenPancakes) {}
private:
entry() {}
};
entry getEntry() {
string personName;
int pancakesEaten;
cout
Actually, just `entry() = default` is fine, the fields will be default-constructed anyway.
I think you have to fill the array at initialisation
Then you can't use an array, because an array has a fixed size and hence requires all members filled at the point of initialisation.
You could do
array
or
array
Damn. I'll just use vector instead
/*Write a program that asks the user to enter the number of pancakes eaten for
breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Modify the program so that it outputs a list in order of number of pancakes
eaten of all 10 people.*/
#include
#include
#include
#include
using namespace std;
struct entry {
public:
string name;
int pancakesEaten;
entry(string& givenName, int givenPancakes)
: name(givenName), pancakesEaten(givenPancakes) {}
private:
entry() {}
};
entry getEntry() {
string personName;
int pancakesEaten;
cout
But the array will try to construct 10 entries when it constructs itself and it'll want to use the default constructor for that.
You can work around that by using std::vector.
What's the correct way to add a couple of functions and override a function for a class? I tried two approaches, both seem to be bad:
1) Just add some functions that operate on the class. But this mixes procedural programming with OOP.
2) Inherit the class. This leaves you with all kinds of cornercases where parent class returns itself and not the child and you have to catch them all.
What's the right way to do it?
Thanks for the pointers. Also sorry for the typos.
t. phoneposter
>be me, work construction. Fuck up my knees
>pick up programming as a way to get a non physical job
>litterally making the easiest and shittiest codes
>never had so much fun in my life
>Dynamically-typed languages
Do you want class methods or plain functions that take class objects as argument?
...
Now I got one more question
struct entry {
public:
string name;
int pancakesEaten;
// notice the string&
entry(string& givenName, int givenPancakes)
: name(givenName), pancakesEaten(givenPancakes) {}
private:
entry() {}
};
entry getEntry() {
string personName;
int pancakesEaten;
cout
I haven't used VS for a while but that worked for me, try pressing R again?
It will copy construct it anyway.
That's it, thanks.
I would prefer class methods because it doesn't mix procedural programming with OOP.
PROGRAMMING CHALLENGE
Make a £sd calculator. It must be able to add, subtract in £sd, multiply and divide by decimal fractions. Lowest coin is farthing.
So far, we have a solution in APL and J!
What other languages will present Sup Forums later?
std strings have a fine copy constructor, it should work ok.
Mixing cin with getline will fuck up your I/O, though.
>Mixing cin with getline will fuck up your I/O, though.
Oh boy. Thanks.
I wonder how many more corner cases there are.
If they compliment the class functionality as a whole, add them to the base class, if they are something new, make a new class that inherits.
If you can't easily come up with a name for the derived class then probably adding to base is the better option.
Of course, you can do something like make a new class that has the base class as a member and add the functions there with some wrappers for the base class. That way you avoid a hard dependency.
Anons, which notebook is best with price < $1000?
I use HP compaq, I bought it new for 200 euro over 2 years ago, runs lubuntu without any problems
What's an inline static virtual variadic extern anonymous constant friend function?
>inline
you can declare it in a header
>static extern
can't be. it's either one or another. static is for traslation-unit linkage, extern is for global linkage.
>virtual
dunno
>anonymous
dunno
>constant
dunno
>friend
dunno
>error: virtual functions cannot be friends
I learn something new about C++ every day.
>can't be. it's either one or another. static is for traslation-unit linkage, extern is for global linkage.
What if it's static in sense that it can only access the static variables in the class?
Since some of those are class method exclusive I'm assuming it is a class method.
>inline
This basicaly asks the compiler to put the code directly into the assembly of whatever called the function instead of calling it.
>static
Independent from class instance
>virtual
Can be overriden by a derived class
>variadic
Has variable number of arguments
>extern
Not sure if it even works in class methods
>anonymous
Doesn't have a name, duh (for example a lambda)
>constant
Can't modify whatever it's called on
>friend
Has access to private and protected fields
Why do you use a language one cannot master?
I don't use C++. I answered this question from C perspective.
>>inline
>This basicaly asks the compiler to put the code directly into the assembly of whatever called the function instead of calling it.
It does nothing besides allowing to declare it multiple times in a header. It does literally nothing else. It's a hint.
You can't master English either and you insist on using it.
That's an extreme corner case anyway, reminds me of shit they put me through at uni. Never used any of the weird syntax they pulled out of their asses.
Lies, I am proficient with 100% of the features of this programming language
I don't do English for a living
gcc interprets inline as asking to make a function faster and it can actually achieve that by inlining it in the assembly
>gcc interprets inline as asking to make a function faster and it can actually achieve that by inlining it in the assembly
It's a hint. The compiler inlines *all* the functions where it sees that fit.
It's like a register keyword, which nowadays is *completely* useless. The inline keyword at least lets you to define the function multiple times.
Compiler is free to ignore it.
I don't do C++ for a living either. I'm paid to solve problems, not know all the obscure features of arbitrarily chosen language.
I'm a Java dev actually and I google most of the Java 8/9 features when at work since you can't possibly remember them all.
> register keyword, which nowadays is *completely* useless
`register` has actually been removed in C++17, now it's an unused reserved word.
Still there in C11.
I don't think any of the popular compilers takes register seriously. It's still reserved in C++17 though so it's open for some cool macro use.
It depends on their backend.
I hope they remove this C feature and C22.
void func(int array[static 1]);
>register is useless
#include
int main(void)
{
int n = 0;
#ifdef REGISTER
register int i;
#else
int i;
#endif
for (i = 0; i < 2000000000; i++)
if (i % 15 == 0)
n++;
printf("%d\n", n);
return 0;
}
>It's a hint. The compiler inlines *all* the functions where it sees that fit.
It's a storage qualifier. Not related to function inlining.