@unchanted
oh, ok
@unchanted
so within a same program i have to create 5 threads one for each philosopher
Anonymous
howe mach I am tride It does not work you can help to write this code?
@unchanted
what if it is not a light weight process?
Anonymous
#include <iostream>
int main() {
int N;
std::cin >> N;
const int arr =1000;
for( int i = 0; i < N; i++){
std::cin >> arr[i];
}
for ( int i = 0; i< N; i++){
std::cout << arr [i] << " ";
}
}
@unchanted
i mean in any certain condition
Anonymous
Write a program that gets a natural number N (N ≤ 1000) at the input, then a sequence of whole N elements. As a result, the program must display the sequence in reverse order. Use array to solve the problem
Alexander
#include <iostream>
int main() {
int N;
std::cin >> N;
int arr[1000];
for( int i = 0; i < N; i++){
std::cin >> arr[i];
}
for ( int i = N-1; i>= 0; i--){
std::cout << arr [i] << " ";
}
}
@unchanted
@lightness_races_in_orbit can you directly share me the code for Dining Philosopher's problem, it is not my homework I promise I need it because by referring that code it will help me in understanding the whole concept and also help me in understanding other problems such as "sleeping barber", "reader-writer", etc..
@unchanted
oh ok
@unchanted
any source (link)?
@unchanted
every tutorial is explaining pseudocode
Anonymous
Alexander
Can anybody help me with std::forward? I have a little trouble:
why when I pass const reference to std::forward it deduce it to just const type whithout reference? Meanwhile without const all works fine.
MyClass myClass; // simple structure with couple variables
MyClass& class_ref = myClass;
std::forward<MyClass&>(class_ref); // all is ok
const MyClass& class_const_ref = myClass;
std::forward<const MyClass&>(class_const_ref); // no instance of overloaded function "std::forward" matches the argument list: (const MyClass)
Bojan_Krdemn
Hey guys, i am looking for somebody who have strong knowledge of algorithms to have a small chat?
Daniele
guys is there any assembly dedicated telegram group? or can we just ask here?
Dima
Dima
but assembly here is kinda allowed too
Daniele
Alexander
void foo(const MyClass& class){
bar(class);
}
void baz(const MyClass& class){
}
template <typename... Args>
void bar(Args&&... args)
{
baz(std::forward<Args>(args)...);
}
Alexander
Thanks for the answer. So far, I have not been able to reproduce the behavior of the program from real code. A little later I will prepare it.
Alexander
Yeah, this code works. But in my full version static analyzer give me this error
@unchanted
@unchanted
what if in this function only "void philosopher" was written instead of "void* philosopher"?
@unchanted
what is the return type of void* func(statement) ?
Alex
pointer of any type(expect you will cast it)
@unchanted
can you elaborate a little?
PO
Who knows gtk?!
Anonymous
/get cbook
piggyho
I found the video, pls tell me what you think.
c++ and beyond atomics part 2, see minute 30:52
https://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-Sutter-atomic-Weapons-2-of-2
PO
PO
^how undrestand this error?
PO
But I can't understand
PO
what is in my case
PO
Mohsen
Hello, in this code I could not how (rand() » 10) & 0x01 works and gives binary elements for data[i]. Same thing for data_int. I cannot understand how is it working. May someone help me about it. for (i=0; i<k; i++)
data[i] = (rand()>>10) & 0x01;
/* convert data[] to integer
data_int = 0;
for (i=0; i<k; i++)
data_int = (data_int << 1) ^ data[i];
Artöm
some_integer & 0x01 gives either 0 or 1. >> 10 is useless here
Mohsen
Artöm
It writes all bits from array into a single integer variable preserving bit order
Artöm
I assume k is sizeof(data_int) * CHAR_BITS
Mohsen
Hermann
Is it possible that the same C code on one machine works and on the other doesn't?
Anonymous
piggyho
depends.
usually when you're seeing this type of behavior there's a memory problem. aka pointer
Anonymous
It's called undefined behavior
piggyho
if you're running Linux install valgrind from the repository and run your app under valgrind
Anonymous
Hermann
Yes
how is it possible? i compile the code
piggyho
there seems to be a lot of confusion here of what a pointer is
Anonymous
Anonymous
How it's possible
Hermann
piggyho
not sure what that means
piggyho
stick with the standards
but you're not understanding that compiling code successfully doesn't mean runtime correct
piggyho
and what happens on the other machine where you say it doesn't work
Hermann
piggyho
is the definition in one of your header files
piggyho
is that header file included in more than .c or .cpp
where is that her file included in another header file
Hermann
piggyho
what is the global value but you're defining
Hermann
piggyho
you might want to post the code so we can have a quick look
Anonymous
Hi first. Am last
Indolent
like what more can be possibly see this year
Indolent
this year is a fuckin' nightmare
Indolent
damn this is probably the deadliest attack in twitter's history
Indolent
almost half of the silicon valley's top dudes just got hacked
Anonymous
thats what happens when ppl hungry
Jaen
Hi I'm using a structure and it looks like this
typedef struct{
int id;
char name[30];
} User;
int main( void ){
User* user;
user = (User*)malloc(30*sizeof(User));
free(user);
user = NULL;
return 0;
}
Jaen
I would like to know if the space reserved for the name is also released when releasing the pointer