structure

Why is DateTime a structure in .Net?

一世执手 提交于 2019-12-06 17:30:40
问题 Why is DateTime a structure instead of an inheritable class? (I would like to be able to override the ToString() method but I can't.) 回答1: Probably because it was seen as a small, simple and immutable data structure, much like an integer or decimal. Making it a struct under these conditions make using a DateTime very efficient. If it had been made a class, this efficiency benefit would have been lost because that would require memory allocations every time you create a new DateTime. Besides,

p is a pointer to a structure, what do all these code snippets do?

余生长醉 提交于 2019-12-06 16:14:17
++p->i p++->i *p->i *p->i++ (*p->i)++ *p++->i I don't understand these statements above, I wrote a small test program to understand them. #include <stdio.h> struct my_structure { int i; }; void main() { struct my_structure variable = {20}; struct my_structure *p = &variable; printf("NAME: %d\n", ++p->i); printf("NUMBER: %d\n", p++->i); printf("RANK: %d", *p->i++); printf("name: %d\n", *p->i++); printf("number: %d\n", (*p->i)++); printf("rank: %d", *p++->i); } Here's what the output I got after I commented the last four print statements: NAME: 21 NUMBER: 21 And after uncommenting the code and

Graph C implementation - Depth first search

走远了吗. 提交于 2019-12-06 16:00:20
问题 I am trying to implement depth first search algorithm using adjacency list representation of graphs. Here is my code: #include<stdio.h> #include<stdlib.h> struct edge { int vertexIndex; struct edge *edgePtr; }edge; struct vertex { int vertexKey; int visited; struct edge *edgePtr; }vertex; void insertVertex(struct vertex *g, int vertexKey, int *vertexCount) { g[*vertexCount].vertexKey=vertexKey; g[*vertexCount].edgePtr=NULL; g[*vertexCount].visited=0; (*vertexCount)++; } void insertEdge(struct

C# Structure - Access class from external library

纵然是瞬间 提交于 2019-12-06 14:03:06
I have a question regarding correct way to structure my application. I am a beginner on C# so excuse if I have some basis missing. I looked on the web(not only stackoverflow) but didn't find any answer, so maybe this is just because I am doing something wrong? I have a project in which there are several classes to define my objects. Object1.class.cs Object2.class.cs ... Now for some functions, I created class libraries (.dll files) to externalise the code. The idea is if I need to make an update, I just need to replace .dll file, and not all the code. But I meet a problem when I want to send

C++ header file parsing

只愿长相守 提交于 2019-12-06 13:51:47
问题 I need to parse a header file. My goal is to search the specific structure from the header file and extract the values and offsets of the structure variables. Can any one please suggest the best way for parsing the header file by omitting the comments and how to parse macros from header too? 回答1: Parsing C++ is tough. You'll likely want to use an existing parser. I know of 4 that are probably useful: Edison Design Group front end Clang's C++ parser DMS Software Reengineering Toolkit and its C

C structure not scanning all the inputs

ぐ巨炮叔叔 提交于 2019-12-06 11:11:29
I have this C code: #include "stdio.h" main() { struct books { char name[100],author[100]; int year,copies; }book1,book2; printf("Enter details of first book\n"); gets(book1.name); gets(book1.author); scanf("%d%d",&book1.year,&book1.copies); printf("Enter details for second book\n"); gets(book2.name); gets(book2.author); scanf("%d%d",&book2.year,&book2.copies); printf("%s\n%s\n%d\n%d\n",book1.name,book1.author,book1.year,book1.copies); printf("%s\n%s\n%d\n%d\n",book2.name,book2.author,book2.year,book2.copies); } What is happening here is that it only scans till the author name of the second

wordpress multisite remove /sites/{ID}/ automatic upload url

家住魔仙堡 提交于 2019-12-06 11:10:01
when using wp multisites it gets messed up pretty fast. Is there any solution available removing the automatic /sites/{id}/ folder structure? I'm able to adjust the site-upload-dir within site-settings but it always adds " /sites/{id}/ " to the uploaded file through the media-manager. Is there any snippet available removing/disabling these extra folder structure? First I ended up changing the core in wp-includes/functions.php in order to disable the addition: if ( defined( 'MULTISITE' ) ) $ms_dir = '/sites/' . get_current_blog_id(); else $ms_dir = '/' . get_current_blog_id(); And one line

nested structure array access in python using SWIG

限于喜欢 提交于 2019-12-06 07:53:50
I haven't been able to figure out how to access the array elements SubStatus in the following nested structure. I do seem to be able to see the first element, but don't understand how to force indexing, e.g., as a list. Any help is much appreciated. status.h: // Data Types typedef char CHAR; // 8 bits signed typedef short SHORT; // 16 bits signed typedef long LONG; // 32 bits signed typedef unsigned char UCHAR; // 8 bits unsigned typedef unsigned short USHORT; // 16 bits usigned #define FUNC_TYPE // built in C, leave reference as C #define DLL_API extern FUNC_TYPE __declspec(dllimport) // Sub

What is the difference between structures containing bool vs uint when using PInvoke?

喜夏-厌秋 提交于 2019-12-06 06:25:20
Ok, I'm now very confused. After my last question had several people comment about changing bool to uint I verified they are the same size by: Console.WriteLine("sizeof bool = {0}", Marshal.SizeOf(typeof(bool))); Console.WriteLine("sizeof uint = {0}", Marshal.SizeOf(typeof(uint))); Which of course prints: sizeof bool = 4 sizeof uint = 4 That said, I then broke down and gave their suggestions a try anyway... Changing a single bool inside a structure to a uint. What I can't figure out for the life of me is why this made it work... So this works: [StructLayout(LayoutKind.Sequential)] public

Options with Options with Python argparse?

时间秒杀一切 提交于 2019-12-06 06:18:47
I'm writing a script in Python, and using argparse to parse my arguments. The script is supposed to compare two different "aligners" from a pool of available aligners, and each aligner has some configuration options. I want to be able to call my script with something like: ./script.py --aligner aligner1 --param 12 --aligner aligner2 --param 30 --other_param 28 I want to get out of this some sort of structure where the first --param option "belongs" to the first --aligner option, and the second --param and the --other_param options "belong" to the second --aligner option. Is argparse capable of