Dima
lol
vinícius*
I do not say anything about my work, how do you know that doing more checks worse than yours?
Imagine comparing it to three extensions, you'd call an O(n) function three times, and then have to compare the resulting subtring. If you reverse it first, you call an O(n) function one time, and then you're left with comparing at max three chars
vinícius*
lmao
vinícius*
anyway, go on and optimize strings comparisons, i got more stuff to do
Cengizhan
Also, it is OK, people can do/suggest wrong things.
PO
Also, it is OK, people can do/suggest wrong things.
It's ok, I'll try several ways, don't worry
Cengizhan
It's ok, I'll try several ways, don't worry
No, it is not. Maybe not for you but someone else will misunderstand/learn from this chunk of code. People have to deal with their mistakes. If it is not good enough, that's OK. Nobody has to prove something here. Anyway, I need to go for string optimization on my work.
Nils
Hi, does C support function overloading like C++?
Nils
No
Thx. Just wrote an entire program using them without testing... Ig I have to rewrite everything 🤣
Dima
Hi, does C support function overloading like C++?
well, you can make a pointer to different functions, lol!
Francisco
There's a good a reason C doesn't allow (and will never do) function overloading, and that is ABI stability
Nils
well, you can make a pointer to different functions, lol!
How did C++ solve that, just out of interest?
Francisco
vtable
What are you talking about?
Nils
vtable
Okay, thx. I'll do some research on that.
Dima
What are you talking about?
I am talking about his first question, my first answer was (obviously) a sarcasm
Francisco
Nils
I am talking about his first question, my first answer was (obviously) a sarcasm
Oh, I read "can't" instead of "can"
olli
How did C++ solve that, just out of interest?
C++ compilers use their own name mangling, e.g. The name of these functions void foo(int) {} void foo(float) {} void foo(long) {} in compiled output are _Z3fooi, _Z3foof and _Z3fool. In the end it's pretty similar to C but the compiler does it for you.
O
C++ Creator Bjarne Stroustrup Weighs in on Distributed Systems, Type Safety and Rust – The New Stack
Anonymous
/get cbook
Anonymous
/get c++ book
Anonymous
/get cppbook
Anonymous
/get c book
Nils
Hi, how do I get the address of the value returned by a function in C?
Nils
As in a pointer to the value
Francisco
int a = foo(); &a // Memory direction of a
Alex
int a = foo(); &a // Memory direction of a
no, this is copy of returned var
Alex
Hi, how do I get the address of the value returned by a function in C?
probably this is impossible. cause var can be returned using register for example. and why do you need this address? in any case this var is temp
Francisco
no, this is copy of returned var
But you can't take the direction of a value returned by a function, as it is a temporary and doesn't have a direction in memory
Nils
:-/
Nils
Thx
Francisco
Unless you return a reference, which belong to C++, or just a pointer
Nils
Alex
to get address just use printf("%p\n", foo()); to free - free(foo())
olli
Can I somehow tell the compiler to free() that returned value as soon as it is no longer in use?
No, you can't do this in C, you have to free it explictely. In C++ you could make use of RAII.
Nils
Okay, thx
Nils
So no matter what, I will have a memory leak.
olli
You should not, can you share your code?
Nils
You should not, can you share your code?
https://hastebin.com/ajamoqaqeg.c
Nils
If you wonder, "db" means "databuffer"
Nils
Whichs struct I could show you too
Nils
struct databuffer { size_t len; char *data; };
olli
Can't you do something like this on the caller side? const struct databuffer* db = auto_db(ptr); // // ... use it // // once you're done, free it free(db);
/home/aleksandr/
Hello! Why it ?
Cengizhan
Hello! Why it ?
Accessing out of bound of array?
/home/aleksandr/
Yea
/home/aleksandr/
32764 where are these numbers?
Cengizhan
So, it is undefined behavior, you cannot be sure that which data is written out of array.
Cengizhan
Probably, garbage data.
/home/aleksandr/
ok, thanks
Nils
char *buffer = NULL; ssize_t size = 0; size = getline(&buffer, 0, input); Hi, why does this result in "invalid argument"?
Nils
First argument of getline is not char pointer, it should be ifstream reference.
getline(char **lineptr, size_t *n, FILE *stream); (man page)
Nils
The last one is a FILE, not the first one
Nils
And no, I am not talking about std::getline
Nils
I am programming in C right now.
Cengizhan
OK, calm down.
Cengizhan
I misunderstand.
Nils
OK, calm down.
Don't worry, I am not angry 😅
Alex
why is it written as input?
Alex
show code for init input var
Nils
why is it written as input?
void db_readline(struct databuffer *db, FILE *input) { char *buffer = NULL; ssize_t size = 0; size = getline(&buffer, 0, input); assert(size == -1); const struct databuffer thisdb = sized_db(buffer, size); db_append(db, &thisdb); }
Cengizhan
Probably, not given &size instead of 0.
Nils
Probably, not given &size instead of 0.
If *lineptr is set to NULL and *n is set 0 before the call, then getline() will allocate a buffer for storing the line.
Cengizhan
Because, size will be filled up by getline implicitly but there is no variable for that.
Alex
Hi, why does this result in "invalid argument"? - this is errno val?
Nils
Why wouldn't stdin work for that?