struct

Modifying struct instance variables within a Dispatch closure in Swift

老子叫甜甜 提交于 2020-01-14 07:24:21
问题 I'm using the DEVELOPMENT-SNAPSHOT-2016-06-06-a version of Swift. I cannot seem to get around this issue, I've tried using @noescape in various places, but I still have the following error: Closure cannot implicitly capture a mutating self parameter To better explain, here is a simple example: public struct ExampleStruct { let connectQueue = dispatch_queue_create("connectQueue", nil) var test = 10 mutating func example() { if let connectQueue = self.connectQueue { dispatch_sync(connectQueue)

Modifying struct instance variables within a Dispatch closure in Swift

只愿长相守 提交于 2020-01-14 07:24:20
问题 I'm using the DEVELOPMENT-SNAPSHOT-2016-06-06-a version of Swift. I cannot seem to get around this issue, I've tried using @noescape in various places, but I still have the following error: Closure cannot implicitly capture a mutating self parameter To better explain, here is a simple example: public struct ExampleStruct { let connectQueue = dispatch_queue_create("connectQueue", nil) var test = 10 mutating func example() { if let connectQueue = self.connectQueue { dispatch_sync(connectQueue)

Is there a way to initialize members of a struct without using a constructor?

女生的网名这么多〃 提交于 2020-01-14 07:16:10
问题 I have a struct that contains two lists: struct MonthData { public List<DataRow> Frontline; public List<DataRow> Leadership; } However, I want to initialize both when the struct is created. If I try: struct MonthData { public List<DataRow> Frontline = new List<DataRow>(); public List<DataRow> Leadership = new List<DataRow>(); } Then I get: Error 23 'MonthData.Frontline': cannot have instance field initializers in structs ... Since structs cannot have parameterless constructors, I can't just

Do nvcc, gcc, clang and msvc “respect” the __restrict__ keyword within structs?

谁都会走 提交于 2020-01-14 04:38:08
问题 Suppose I have struct s { int* __restrict__ p1; double v; }; void foo(int* __restrict__ p2, struct s my_s) { /* ... */ } Do the C++ compilers listed below respect the __restrict__ keywords in this case, and assume memory accesses through p2 cannot affect accesses through p1 ? Obviously this is compiler-dependent, since restrict is not a C++ keyword. I'm mainly interested in the answer for gcc 4.9.x and nVIDIA CUDA 7.5's nvcc (when compiling device code of course, not when forwarding to a host

incompatible return type from struct function - C

不羁岁月 提交于 2020-01-14 04:34:05
问题 When I attempt to run this code as it is, I receive the compiler message "error: incompatible types in return". I marked the location of the error in my code. If I take the line out, then the compiler is happy. The problem is I want to return a value representing invalid input to the function (which in this case is calling f2(2).) I only want a struct returned with data if the function is called without using 2 as a parameter. I feel the only two ways to go is to either: make the function

How to access member of struct dynamically in C?

混江龙づ霸主 提交于 2020-01-14 03:57:26
问题 I have two structs and array of const chars: typedef struct { int skip_lines; int num; // count of files int i; // number of the file to define order; extremly important to set correctly and then not to change! char filename[70]; char main_directory[16]; char submain_directory[100]; } FILE_; typedef struct { FILE_ radiation_insolation[7]; FILE_ radiation_radiation[5]; FILE_ winds[9]; FILE_ pressure[1]; FILE_ humidity[1]; FILE_ temperature[4]; } FILES; char *tables[] = {"radiation_insolation",

How to access member of struct dynamically in C?

白昼怎懂夜的黑 提交于 2020-01-14 03:57:07
问题 I have two structs and array of const chars: typedef struct { int skip_lines; int num; // count of files int i; // number of the file to define order; extremly important to set correctly and then not to change! char filename[70]; char main_directory[16]; char submain_directory[100]; } FILE_; typedef struct { FILE_ radiation_insolation[7]; FILE_ radiation_radiation[5]; FILE_ winds[9]; FILE_ pressure[1]; FILE_ humidity[1]; FILE_ temperature[4]; } FILES; char *tables[] = {"radiation_insolation",

Hiding C struct definition

陌路散爱 提交于 2020-01-13 20:28:34
问题 Here is my setup: In public.h: #ifndef PUBLIC_H_ #define PUBLIC_H_ #include "func.h" /*extern typedef struct _my_private_struct PRIVATE_;*/ typedef struct _my_private_struct PRIVATE_; /* Thanks to larsmans and Simon Richter */ #endif In struct.h #ifndef STRUCT_H_ #define STRUCT_H_ struct _my_private_struct { int i; }; #endif In func.h: #ifndef FUNC_H_ #define FUNC_H_ #include "struct.h" /* typedef struct _my_private_struct PRIVATE_; */ extern PRIVATE_ * get_new(int); #endif In func.c:

All possible combinations of many parameters MATLAB

余生颓废 提交于 2020-01-13 19:00:28
问题 I have a list of parameters and I need to evaluate my method over this list. Right now, I am doing it this way % Parameters params.corrAs = {'objective', 'constraint'}; params.size = {'small', 'medium', 'large'}; params.density = {'uniform', 'non-uniform'}; params.k = {3,4,5,6}; params.constraintP = {'identity', 'none'}; params.Npoints_perJ = {2, 3}; params.sampling = {'hks', 'fps'}; % Select the current parameter for corrAs_iter = params.corrAs for size_iter = params.size for density_iter =

How to read through data in a file, and pass it to a struct ~> C

依然范特西╮ 提交于 2020-01-13 18:05:42
问题 Okay. I have a file called "Graduates.txt" in my home directory. I have a portable program to find the home directory, and I opened the file for reading. Data in the file looks something like this: year,firstName,lastName I need to get this data from this file, and separate it into my struct: typedef struct alumnus { int yearGraduated; char firstName[30]; char lastName[30]; } Alumns; I have a thought that may or may not work: A while loop reads through the file, using fgets() to get the data.