@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
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
but assembly here is kinda allowed too
klimi
guys is there any assembly dedicated telegram group? or can we just ask here?
* C/C++ discussion preffered (assembly also allowed), asking about other languages (or groups for other languages) right after joining will get you BANNED.
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)...); }
Daniele
but assembly here is kinda allowed too
i will eventually ask here when I'll be banging my head on the assembly inline project we have to do
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?
I_Interface
^how undrestand this error?
Have you tried to google this error?
PO
Have you tried to google this error?
there is only one page with exact error
PO
But I can't understand
PO
what is in my case
I_Interface
there is only one page with exact error
I didn't meet this "gtk", probably debug will help u.
I_Interface
I'm trying but gtk is real shit
Try to comment strings of code, idk what else to do :D
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
some_integer & 0x01 gives either 0 or 1. >> 10 is useless here
Thanks, I got. May you help how the second loop works.
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
Hermann
Is it possible that the same C code on one machine works and on the other doesn't?
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
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
It's called undefined behavior
I've already told you
Anonymous
How it's possible
piggyho
how is it possible? i compile the code
compiling doesn't mean that it's run time correct it just means that it's syntactically correct
piggyho
not sure what that means
Hermann
not sure what that means
how can you write c code that works for all machines?
piggyho
stick with the standards but you're not understanding that compiling code successfully doesn't mean runtime correct
Hermann
stick with the standards but you're not understanding that compiling code successfully doesn't mean runtime correct
are there any particular flags on gcc for this ?. I understand what you say, but the code compiles and outputs the expected values.
piggyho
and what happens on the other machine where you say it doesn't work
piggyho
is the definition in one of your header files
Hermann
is the definition in one of your header files
in the header file i define global value and in .c file i write extern myvalue
piggyho
is that header file included in more than .c or .cpp where is that her file included in another header file
Hermann
is that header file included in more than .c or .cpp where is that her file included in another header file
in c. file i use incluce myheader and in h. file use #ifndef LIB_main_H #define LIB_main_H
piggyho
what is the global value but you're defining
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