sizeof

Reading data from Dukascopy tick binary file

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have downloaded the Dukascopy tick data and I have decompressing it with easylzma library. The original compressed binary file is EURUSD/2010/00/08/12h_ticks.bi5 (EURUSD/2010/ian/8/12h) After decompressing we get the following format: +-------------------------+--------+-------+ | time | Bid | Ask | +-------------------------+--------+-------+ 000003CA 00022EC0 00022EB6 40CCCCCD 41180000 000004F5 00022EB6 00022EB1 4099999A 404CCCCD (You can download original compressed file from: EURUSD/2010/00/08/ 12h_ticks.bi5 . After decompressing it

Write a program that will print “C” if compiled as an (ANSI) C program, and “C++” if compiled as a C++ program

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Taken from http://www.ocf.berkeley.edu/~wwu/riddles/cs.shtml It looks very compiler specific to me. Don't know where to look for? 回答1: Simple enough. #include int main(int argc, char ** argv) { #ifdef __cplusplus printf("C++\n"); #else printf("C\n"); #endif return 0; } Or is there a requirement to do this without the official standard? 回答2: We had to do a similar assignment at school. We were not allowed to use preprocessor (except for #include of course). The following code uses the fact that in C, type names and structure names form

What should happen to the negation of a size_t (i.e. `-sizeof(struct foo)`))?

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm dealing with some code at work that includes an expression of the form -(sizeof(struct foo)) i.e. the negation of a size_t , and I'm unclear on what the C and C++ standards require of compilers when they see this. Specifically, from looking around here and elsewhere, sizeof returns an unsigned integral value of type size_t . I can't find any clear reference for specified behavior when negating an unsigned integer. Is there any, and if so, what is it? Edit: Ok, so there are some good answers regarding arithmetic on unsigned types, but it

OpenSSL AES 256 CBC via EVP api in C

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What I am trying to do: Write a program in C that opens a file of arbitrary size and reads its contents. Once The contents are read it will encrypt them in AES 256 CBC and save the ciphertext to a file called ciphertext. Once this is saved it will close both files. Then will open the cipher text from the file that was just saved and decrypt the cipher text and save it to a file called decrypted. My Problem: It seems to never decrypt my cipher text. I get garbage, I have no idea what I am doing wrong. Please help. #include #include #include

GSSendEvent - Inject Touch Event iOS

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to inject touch event in iPhone. I get the coordinates of touch event via network socket. GSSendEvent seems to be good choice. However, it needs GSEventRecord as one of the inputs. Does anyone know how to prepare GSEventRecord? I prepared it based on some examples but the app crashes after GSSendEvent call. Appreciate any help. -(void) handleMouseEventAtPoint:(CGPoint) point { static mach_port_t port_; // structure of touch GSEvent struct GSTouchEvent { GSEventRecord record; GSHandInfo handInfo; } ; struct GSTouchEvent *touchEvent =

How to implement fast inverse sqrt without undefined behavior? [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: What's a proper way of type-punning a float to an int and vice-versa? 6 answers From what I understood about strict aliasing rule , this code for fast inverse square root will result in undefined behavior in C++: float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &y; // type punning i = 0x5f3759df - ( i >> 1 ); y = * ( float * ) &i; y = y * ( threehalfs - ( x2 * y * y ) ); return y; } Does this code indeed cause UB? If

SCSI Read(10) on a Physical Drive on Windows

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I tried issuing a SCSI Read(10) command to a physical drive on a Windows 7 machine. Below is the code snippet that I am using. It is failing with error code 87. void scsi_read() { const UCHAR cdb[10] = { 0x28, 0, 0, 0, 0, 0, 0, 0, 512, 0 }; UCHAR buf[512]; BYTE senseBuf[196]; const int SENSE_LENGTH = 196; LPCSTR fname = "\\\\.\\E:"; HANDLE fh; DWORD ioctl_bytes; DWORD err = 0; SCSI_PASS_THROUGH s = {0}; memcpy(s.Cdb, cdb, sizeof(cdb)); s.CdbLength = 10; s.DataIn = SCSI_IOCTL_DATA_IN; s.TimeOutValue = 30; s.Length = sizeof(SCSI_PASS_THROUGH);

Is an empty vector the size of its struct?

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Say I have a struct like this: struct vertexNodeInfo { unsigned char level; int node; double leaf; }; If I then had this: vector<vertexNodeInfo> node; How big (memory-wise, not .size ) would the empty vector be, before any push_back ? Would it be exactly the same size (again, in terms of memory) as vector<int> node; ? 回答1: There's no requirement. Even more, it's a poorly formulated question. The .size of the vector would be 0 , because it has no elements. The sizeof isn't affected the number of elements, and is typically large enough to

is_container trait fails on std::set SFINAE issue

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to write a stream operator for std containers, mainly for the purpose of debugging. I have the following code: #include #include #include #include #include #include #include #include #include template struct is_container { typedef char no ; typedef long yes ; template struct is_of_type ; template static yes & is_cont ( is_of_type < typename T :: iterator ( T ::*)(), & T :: begin , & T :: end >*); template static no & is_cont (...); //any other template struct is_class_is_container { const static bool value = sizeof ( is

enum values: NSInteger or int?

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: tl;dr Version How are the data types of an enum's constants guaranteed to be NSUInteger instead of unsigned int when declaring an enum thusly: enum { NSNullCellType = 0, NSTextCellType = 1, NSImageCellType = 2 }; typedef NSUInteger NSCellType; The typedef to NSUInteger does not appear to be tied to the enum declaration in any way. Full Version I was reading through Apple's 64-Bit Transition Guide for Cocoa for some guidance on enum values and I came away with a question. Here's a (lengthy) quote from the Enumeration Constants section,