Ajay
I'd say type is obvious here
Assume that the type is set<int>::iterator
Ajay
It is not allowed
you mean UB?
Artöm
Yep
Ajay
🆗
@unchanted
temp is your buffer
did you mean temp size ? because temp is of char data type and buffer is of int datatype
Artöm
Buffer for fgets is char array, I meant that
@unchanted
oh sorry i was talking about maxcount
@unchanted
ok i got it
@unchanted
Thanks by the way 😅
Artöm
@Tanmaykumar1 how do you learn C btw? By some book or video course or something else?
@unchanted
let us c
@unchanted
and one channel from Cherno
@unchanted
let us c
though i didn't read it completely (i skipped windows.h and linux chapter)
Artöm
I learned C++ on learncpp.com and then watched tons of videos fron various C++ conferences. I also participated in similar chat activity but in my native language. As a result I know fair amount of C
Anonymous
let us c
lol give output of int i = 5; printf("%d %d %d\n", ++i, i, i++);
Кирилл 🤤
Hello, guys. I have some problems with cmake linking libraries in .h and .hpp files. Maybe, somebody can help me: https://stackoverflow.com/questions/63097225/cannot-linking-cmake-targets
@unchanted
no 7 7 5 😂😂
Кирилл 🤤
Anonymous
Hello, guys. I have some problems with cmake linking libraries in .h and .hpp files. Maybe, somebody can help me: https://stackoverflow.com/questions/63097225/cannot-linking-cmake-targets
add_library(A INTERFACE) target_include_directories(A INTERFACE directory/containing/a.h) add_executable(B b.cpp) // b.cpp contains #include "a.h" target_link_libraries(B PUBLIC A) // can be PRIVATE, doesn't matter for executable
Anonymous
no 7 7 5 😂😂
it's undefined behaviour due to unsequenced access to the same variable multiple times.
Anonymous
the ultimate fault of Let Us C
@unchanted
the ultimate fault of Let Us C
hmm yeah i just read that book once
Anonymous
no. unspecified behaviour is only the order of evaluation of the arguments. using that unspecified behaviour to modify the same variable twice is undefined behaviour.
@unchanted
Tbh that seems okay
yeah it is working and showing the result 7 7 5
Anonymous
yeah it is working and showing the result 7 7 5
clang -Weverything -O3 -fpedantic
Anonymous
Try with that
Anonymous
we were talking about C where sequence points are a thing
Anonymous
@unchanted
we were talking about C where sequence points are a thing
no ,but still it is working on c compiler too
Anonymous
the ultimate fault of Let Us C
is not teaching terminology of the standard and inventing new terminology for stuff no one cares about
Anonymous
no ,but still it is working on c compiler too
https://stackoverflow.com/questions/2397984/undefined-unspecified-and-implementation-defined-behavior
@unchanted
ok ok, just leave it.. 😅😅
Anonymous
ok ok, just leave it.. 😅😅
yeye. i just hate that book and that question specifically
Anonymous
because when you argue with the profs they just deduct your marks instead of accepting the dumbasses they are
@unchanted
yeye. i just hate that book and that question specifically
you hate it still you read it? even more-than once, I think, as you were so quick to bring that fault 😂😂
Anonymous
you hate it still you read it? even more-than once, I think, as you were so quick to bring that fault 😂😂
i never actually read the book. just skimmed some pages once. that question is known throughout india though.
Anonymous
and i know it originated due to Kanetkar and Balaguruswamy
Artöm
Because array size must be known at compile time
Artöm
Use malloc for reverse array
@unchanted
Use malloc for reverse array
Do you mean dynamic allocation?
Artöm
Yes
@unchanted
ok thanks
Patrick
Are multi-line preprocessor definitions possible? I have 7 lines of code I need to repeat with just on operator different and would rather not copy-paste, like, 10 times
Patrick
Awesome! And am I able to pass and substitute operators like += to it?
@unchanted
#include<stdio.h> #include<stdlib.h> int main() { char temp[100]; printf("enter the character value:\n"); fgets(temp,100,stdin); int i ; i = (int)malloc(sizeof(int)*2); for (i = 0; temp[i] != '/0'; i++) { } char reverse[i+ 1]; int len = i + 1; for (int j = 0; j < len; j++) { reverse[j] = temp[i - j]; i--; printf("%c", reverse[j]); } return 0; } i used malloc this time but it is still showing the same issue
Anonymous
Awesome! And am I able to pass and substitute operators like += to it?
You realize that by putting a \ at the end you're just escaping the newline?
Patrick
You realize that by putting a \ at the end you're just escaping the newline?
I get how it works across a few languages, it's okay
Patrick
I get how it works across a few languages, it's okay
so long as it's part of the same DEFINE it's alright
Anonymous
Also you do not cast when calling malloc
Patrick
(I'll try it out and see how it goes first)
@unchanted
Also you do not cast when calling malloc
oh, how can i do that, can you guide me a little?
Anonymous
oh, how can i do that, can you guide me a little?
You do not do this in C: int* a=(int*) malloc(sizeof(int)); You do this: int* a=malloc(sizeof(int)); You only cast in C++
@unchanted
ok
Patrick
Doing #define ARITH_OP(OPERATOR) ... sum OPERATOR stack[a].as.num; \ ... And calling ARITH_OP(+=) is exactly what I hoped for.
Anonymous
Also your loop is empty
@unchanted
Also your loop is empty
i just needed the value of i. compiler doesn't care if the loop is empty
@unchanted
Then why did you write the loop?
so that the value of i is incremented till the value of temp[i] !='/0' which means i is the length of the given string
Patrick
Yes, it's working fantastically
@unchanted
You can use strcspn/strlen for getting the string length
there was a restriction in this question for not using string function else i would have used strrev() already....
@unchanted
Why is there a restriction?
to understand the algorithm behind the concept of strrev()
Anonymous
static void reverse_byte_array(uint8_t *arr, int len) { int i; char temp; for (i = 0; i < len / 2; i++) { temp = arr[i]; arr[i] = arr[len - i - 1]; arr[len - i - 1] = temp; } }
Anonymous
This might work