/
Is file size your main concern?
no i want to not use too much memory
/
i dont want
Vladimir
but why should i use a string for bytes
Ah, you need bytes, not characters? Well, use std::vector<std::byte> or std::vector<unsigned char>. Char is typically 1 byte size.
mito
I want to create a void pointer pointing to a specific address. The address is a combination of int and some hex value e.g address = 536457346 + 0x1F can I just do (void*)(536457346 + 0x1F) or do I have to explicitly convert that hex to int like (int)0x1F ? #cpp
mito
I'm getting this warning 'type cast': conversion from 'int' to 'void *' of greater size I don't understand what this means.
'''''''
int countSubsets(vector<int> a, int sum) How can I pass another default integer variable n, but set it's value to a.size()?
\Device\NUL
It means the pointer size and int is different
For example, 64 bit ABI use 64 bit pointer, *nix use lp64 while windows use llp64. int is both 32 bit but pointers are 64 bit
'''''''
like int countSubsets(vector<int> a, int sum, int n=a.size())(i know this syntax is invalid, hence I'm asking) this is a recursive function, so I cannot define n inside the function
\Device\NUL
For example, 64 bit ABI use 64 bit pointer, *nix use lp64 while windows use llp64. int is both 32 bit but pointers are 64 bit
It doesn't matter if the ram is below 4 GB, 32 bit still can hold it. It if greater than that, it will overlow
'''''''
'''''''
but still a good idea, thanks
\Device\NUL
Use size_t or ssize_t for casting
mito
It doesn't matter if the ram is below 4 GB, 32 bit still can hold it. It if greater than that, it will overlow
So I have converted a 32bit int to a 64bit because I casted it to a void pointer that is 64 bit?
\Device\NUL
Shrivatsa
Can anyone give some advice I want to build project in C-programming
\Device\NUL
Ahh ok, I understand.
Use uint64_t or size_t to cast it. Best practice is size_t as different system can use different data model
\Device\NUL
So, (void*)((size_t)(374747+0x1F)) ?
I think size_t cast is useless here, at the end it will treated as pointer
Ammar
Use uint64_t or size_t to cast it. Best practice is size_t as different system can use different data model
Casting from pointer to integer and vice versa should use uintptr_t or intptr_t. Not size_t. Because the pointer size can be bigger than the size_t. For example: C compilers on x86 real mode can have 32 bit FAR or HUGE pointers but size_t is still 16 bits.
Levi
let us c
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, so I was trying to write on shared memory. It should be an easy task, the problem is, I can't get it to work. I tried this: Given the fact that char *addr= shmat(stuff); and the file is opened this way: int fd= open(stuff); I tried this: write(fd, addr, SIZE); but it does not write stuff, could please explain me why? Thank you!
/
hi i need help
/
i want to try using smart pointers
/
i need to create a char * using a smart pointer
/
std::unique_ptr < char > ret ( new char [ size + 1 ] () );
/
i tried this but if i use it on file -> read ( ret, size ); it says cannot convert
/
cannot convert to char *
/
i tried this now but it still not work auto ret = std::make_unique < char [] > ( size );
/
it tells me cannot convert unique_ptr < char [] > to char *
/
i have solved it using the get method
/
in the pointer class
RaHuL
Can anyone help..! How to print a "string" using for loop ?
RaHuL
Leave it... I have solved
Anonymous
C
Pavel
std::unique_ptr < char > ret ( new char [ size + 1 ] () );
You can't store a pointer to char array as pointer to char, because it would be deleted incorrectly. You need to use std::unique_ptr<char[]>. Also consider std::vector, which can solve the same tasks, but will provide more useful functionality. As someone mentioned on stackoverflow, the only time you need unique_ptr of C-array is when you don't have std::vector available for some reason.
Pavel
i tried this now but it still not work auto ret = std::make_unique < char [] > ( size );
I'm not sure there's make_unique version for arrays, you may need to do it old way with std::unique_ptr<char[]> a(new char[size]);
Pavel
it tells me cannot convert unique_ptr < char [] > to char *
Actually this code seems to compile for me, are you sure the compiler complaining about this line and not some other line after? Yes, it seems to be valid by the docs https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique
Naman
If anyone can suggest some good book for dsa!
S
you can search in your nearest library.
Roxifλsz 🇱🇹
/warnlimit 3
klimi
/unban 1406106635
Roxifλsz 🇱🇹
/warntime 12w
klimi
/warntime 12w
didn't know that even existed
Anonymous
Hi
Dima
Dima
bruhh
Dima
try posting link with spaces
k4leg
0x0 [dot] st [slash] o164.c Do I understand correctly that this is a bug in ncurses 6.3 (or curses in general): the color pair is not updated in some cases? To reproduce in the above program: press jjkk (fg=6, fg=7, fg=0) or jhll (bg=7, bg=0, bg=1) when starting. If replace line 170 (the end of the endless loop, refresh();) with clear(); print_asterisks(screen_resolution, resolution); then everything is fine.
Lyroy
Hey, is there any way to get notified when a boost::process::child has terminated its execution without polling child.running()?
Hussein
but then there are two processes running? i need one.
you can’t do this with threads using a child process is better because you can ask the OS to stop anytime
Hussein
you can’t do this with threads using a child process is better because you can ask the OS to stop anytime
also you can do this with signals which gives you more options you may stop , terminate , kill a process ..etc you can google each signals for linux or mac os and use them
Hussein
You may need to look at cross-platform frameworks like Boost or Qt.
yeah boost and Qt can do that too if you were doing it in C++ I thought you were coding in C but this is also how to do it natively in C++ too using kernel libraries choose whatever you like but the concept is the same 1- you create a fork (child process) 2- the fork calls your function 3- whenever you want your main function can ask the OS to kill the fork you can do this with threads but you will lose your sanity dealing with race conditions and undefined behavior in addition to mutex locks that will slow your program A LOT!!!
FB
i made a program for bot how do i put it in bot
pavel
generally locks slows your program
Why do you think process is faster than threads? It's almost the same things
Hussein
Why do you think process is faster than threads? It's almost the same things
it is not, but locks that prevent race condition slow programs with multiprocessing it is easier to kill a child whether with another fork or its parent meanwhile controlling other threads is as simple as controlling a process
pavel
If you have a race condition you must to handle it in process as well as in threads. But process synchronization in more complicated
Hussein
If you have a race condition you must to handle it in process as well as in threads. But process synchronization in more complicated
yeah but he doesn’t need to synchronise it unless he is accessing a shared memory between the two processes he ask for a way to run a function in parallel then to be able to stop its execution with threads this is more complicated
pavel
Yes, you should pay much attention to be able stop thread in legal way
Муртазо
Hello guys I am trying to run some code in vscode. Precisely, I am using math.h library in c to round up some numbers. gcc main.c /usr/bin/ld: /tmp/cckUWZE6.o: in function `main': main.c:(.text+0x4e): undefined reference to `ceil' collect2: error: ld returned 1 exit status However it is saying like this. What can be problem? It is working in online compilers.
Amir.M
No matching function for call to Player::Player() Friends, what is this error about, I can't understand?!
Amir.M
No, this error occurs in the constructor definition of another class and has nothing to do with the Player class
Amir.M
I get this error in the constructor implementation of another class where I used Player class objects
● Igor
I get this error in the constructor implementation of another class where I used Player class objects
i believe its because your Player constructor expects some arguments and you are trying to instantiate it with no arguments
Amir.M
i believe its because your Player constructor expects some arguments and you are trying to instantiate it with no arguments
I want to use an array of the Player class in another class, which I am having trouble with
Amir.M
That is, with the definition[5]Player mp, because arguments are not given to objects, does this problem arise?