c

Compile-time assertion to determine if pointer is an array

白昼怎懂夜的黑 提交于 2021-02-19 03:12:55
问题 Currently, I have the following block of code to make safe string copying (it works): #define STRCPY(dst, src) do { assert(((void*)(dst)) == ((void*) & (dst))); \ strlcpy(dst, src, sizeof(dst)); } while (0) So it accepts the construction like: const char *src = "hello"; char dest[5]; STRCPY(dest, src); //hell And denies the following: void (char *dst) { STRCPY(dst, "heaven"); //unknown size of dst } The problem is that the block of code creates an assertion. Is there a way to perform this

Compile-time assertion to determine if pointer is an array

半世苍凉 提交于 2021-02-19 03:12:00
问题 Currently, I have the following block of code to make safe string copying (it works): #define STRCPY(dst, src) do { assert(((void*)(dst)) == ((void*) & (dst))); \ strlcpy(dst, src, sizeof(dst)); } while (0) So it accepts the construction like: const char *src = "hello"; char dest[5]; STRCPY(dest, src); //hell And denies the following: void (char *dst) { STRCPY(dst, "heaven"); //unknown size of dst } The problem is that the block of code creates an assertion. Is there a way to perform this

Why does LC_SYMTAB have invalid stroff/strsize but only for some loaded images?

筅森魡賤 提交于 2021-02-19 03:10:23
问题 I wrote the below program to iterate over all images in memory and dump their string tables. #include <mach-o/dyld.h> #include <stdio.h> #include <string.h> int main(int argc, char** argv) { uint32_t count = _dyld_image_count(); for (uint32_t i = 0 ; i < count ; i++) { const char* imageName = _dyld_get_image_name(i); printf("IMAGE[%u]=%s\n", i, imageName); const struct mach_header* header = _dyld_get_image_header(i); if (header->magic != MH_MAGIC_64) continue; struct mach_header_64* header64

arm compiler 5 do not fully respect volatile qualifier

瘦欲@ 提交于 2021-02-19 02:59:27
问题 Consider the following code: volatile int status; status = process_package_header(&pack_header, PACK_INFO_CONST); if ((((status) == (SUCCESS_CONST)) ? ((random_delay() && ((SUCCESS_CONST) == (status))) ? 0 : side_channel_sttack_detected()) : 1)) { ... } Which generates this machine code (produced with the toolchain's objdump ): 60: f7ff fffe bl 0 <process_package_header> 64: 9000 str r0, [sp, #0] /* <- storing to memory as status is volatile */ 66: 42a0 cmp r0, r4 /* <- where is the load

How should I read Intel PCI uncore performance counters on Linux as non-root?

喜欢而已 提交于 2021-02-19 02:43:06
问题 I'd like to have a library that allows 'self profiling' of critical sections of Linux executables. In the same way that one can time a section using gettimeofday() or RDTSC I'd like to be able to count events such as branch misses and cache hits. There are a number of tools that do similar things (perf, PAPI, likwid) but I haven't found anything that matches what I'm looking for. Likwid comes closest, so I'm mostly looking at ways to modify it's existing Marker API. The per-core counters are

optimizing array loop in c

孤街醉人 提交于 2021-02-19 02:38:19
问题 I have looked online and in my books but I can't seem to get this. I was asked to optimize a small part of a program. Specifically to take an array and add its contents within a small amount of time, with vi and gcc, without using the built-in optimizer. I have tried loop unrolling and a couple of other optimizations meant for products. Can you please help? int length = ARRAY_SIZE; int limit = length-4; for (j=0; j < limit; j+=5) { sum += array[j] + array[j+1] + array[j+2] + array[j+3] +

Linking with another start-up file

你说的曾经没有我的故事 提交于 2021-02-19 02:37:09
问题 I am trying to link a program with my own start-up file by using the STARTUP directive in a LD script: ... ENTRY(_start) STARTUP(my_crt1.o) ... GCC driver is used to link the program (not to bother with library paths like libgcc, etc.): gcc -T my_script.ld ... Unfortunately, it only works with a GCC compiled for powerpc targets, while arm or i686 targets don't and still include crt0.o in collect2. For example: arm-eabi-g++ -v -T my_script.ld ... gives me: collect2 ... /opt/lib/gcc/arm-eabi/4

How should I use Sqlite “PRAGMA integrity_check” in C

对着背影说爱祢 提交于 2021-02-19 02:29:10
问题 I have corrupted database. In commandline I typed PRAGMA integrity_check and sqlite returned On tree page 441 cell 17: Rowid 205 out of order (min less than parent max of 12258) On tree page 26 cell 12: 2nd reference to page 441 On tree page 26 cell 12: Child page depth differs On tree page 26 cell 13: Child page depth differs Page 65 is never used Page 66 is never used wrong # of entries in index sqlite_autoindex_TBL_1 In my c program I typed sqlite3 *glbDBHandle; sqlite3_open(DB_FILE,

find nan in array of doubles using simd

試著忘記壹切 提交于 2021-02-19 02:18:03
问题 This question is very similar to: SIMD instructions for floating point equality comparison (with NaN == NaN) Although that question focused on 128 bit vectors and had requirements about identifying +0 and -0. I had a feeling I might be able to get this one myself but the intel intrinsics guide page seems to be down :/ My goal is to take an array of doubles and to return whether a NaN is present in the array. I am expecting that the majority of the time that there won't be one, and would like

Convert RGB array to Mat (OpenCv)

蹲街弑〆低调 提交于 2021-02-19 02:11:20
问题 I've been trying to convert an array [R,G,B,..] in Mat object with opencv. But is returning wrong data, someone knows why? double data[12] = {0,0,255,0,0,255,0,0,255,0,0,255}; Mat src = Mat(2,2, CV_16UC3, data); and returns: M = [0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 57344, 16495] EDIT: Solved! use uchar instead double, and CV_8UC3 回答1: i think, you wanted: uchar data[12] = {0,0,255,0,0,255,0,0,255,0,0,255}; Mat src = Mat(2,2, CV_8UC3, data); (all red, 2x2 rbg image) 来源: https://stackoverflow.com