Skip to content
Advertisement

Tag: c++

Why does running C code in Vim skip scanf()?

I’m using neovim in arch linux with the gcc C compiler, this is what I use in my .vimrc to compile and run map <F5> :w <CR> :!gcc % -o %< && ./%< <CR> The issue is that my code will run fine but any scanf() functions won’t prompt an input and will be ignored as the program will runs.

C socket programming errors

It’s been an hour since I started looking for THE error. I just started C sockets. The program exits with code -1 after printing “Error 1 connection error”. The server in online, it’s a netcat server. Where did I messed up ? Answer Due to operator precedence, the expression is actually equal to That is, you assign the result of

Why open() has no ‘fd’ return in linux 1.0?

Since there is no return of ‘fd’, how does it read/write later for? ex: Answer open returns a value in there. The cast-to-void is used to signal the compiler that the return value is being deliberately ignored. The init function is the one where the current thread is prepared to execute the init program in user-space. init will expect the

How does pthread_cond_wait (conditon variable) unblock all threads only once, not multiple times?

I have successfully implemented a producer thread and 2 worker threads or consumer threads. The producer thread broadcasts condition using pthread_cond_broadcast. And the worker threads are blocked by pthread_cond_wait. The code looks something likes this: Thread 1 (Producer Thread): Thread 2 (Worker/Consumer Thread): Thread 3 (Worker/Consumer Thread): My question is why does Thread 2 or Thread 3 does not re-execute

Dynamic expansion of the Linux stack

I’ve noticed the Linux stack starts small and expands with page faults caused by recursion/pushes/vlas up to size getrlimit(RLIMIT_STACK,…), give or take (defaults to 8MiB on my system). Curiously though, if I cause page faults by addressing bytes directly, within the limit, Linux will just regularly segfault without expanding the page mapping (no segfault though, if I do it after

Code works logically on macOS but not on Ubuntu 16.04.5

I have a task to write the function: int read_palindrome(); // input comes from stdin which will read one line from standard input and returns 1 if the line is a palindrome and 0 otherwise. A line is terminated by the newline character (ā€™nā€™) and the does not include the newline. There are requirements to be met: There is no

Advertisement