Skip to content
Advertisement

Tag: c++

Strange pointer position in the stack

I wrote this simple code: and I’ve disassembled it to see what the compiler does. Using objdump I obtain: I can understand everything except for the mov QWORD PTR [rbp-0x10],0x0, this correspond (I think)to p=NULL; but from mov QWORD PTR [rbp-0x8],rax I know that my pointer is on rbp-0x8 and it seems correct (the size of a pointer is 8bytes).

Buggy simple function for binary search (C++)

I wrote a simple function for binary search, but it’s not working as expected. I have a vector with 4000000 32-bit ints. Usually, when I search for a number, if it’s there, it’s found and the index is returned, if it’s not, -1 is returned (the index always corresponds to the value, but that’s not the point). While messing around

How to properly print file content to the command line in C?

I want to print the contents of a .txt file to the command line like this: The file testfile.txt looks like this: The function prints only the first 4 letters line. When using sizeof instead of strlen the whole file is printed. Why is strlen not working? Answer When using sizeof instead of strlen the whole file is printed. Why

Managing Log File Sizes

I am implementing a simple log file handler for an embedded device. I cannot use syslog because it is already reserved for other uses. The device’s SSD size is limited, so there is a real risk of the log file using all of the disk space, which will crash the device. What is the cheapest way I can guarantee I

What is the type of elements of thread_group list in sched.h?

In sched.h, task_struct has following 2 fields: thread_group & thread_node. They keep the first element of their list but I could not find which type of variables they contain. Answer thread_group and thread_node are both intrusive linked-lists of all the threads in a thread group – they are use to link together task_structs, they don’t “contain” anything. The difference between

Linux get context switch timing

I’m implementing some form of internal profiler. Is there a way to know when and for how long a thread is context switched out? I know windows has it w the event tracing api and I know perf logs how many context switches happens. Is there a way to do it on linux? Needing root privileges is not an issue

Why makecontext’s func only accepts integer arguments

The man page for makecontext states that the arguments after argc should be integer(int) only: …the function func is called, and passed the series of integer (int) arguments that follow argc If we look at pthread_create or clone system call, they have one void* argument which is to passed to the func, and a pointer of struct can contain any

Advertisement