indirection

How to iterate over an array using indirect reference?

可紊 提交于 2019-12-27 11:05:03
问题 How can I make this code work? #!/bin/bash ARRAYNAME='FRUITS' FRUITS=( APPLE BANANA ORANGE ) for FRUIT in ${!ARRAYNAME[@]} do echo ${FRUIT} done This code: echo ${!ARRAYNAME[0]} Prints APPLE . I'm tryng to do something similar but with "[@]" to iterate over the array. Thanks in advance, 回答1: ${!ARRAYNAME[@]} means "the indices of ARRAYNAME ". As stated in the bash man page since ARRAYNAME is set, but as a string, not an array, it returns 0 . Here's a solution using eval . #!/usr/bin/env bash

Keeping objectiveC object valid outside the scope of a function

时光总嘲笑我的痴心妄想 提交于 2019-12-24 19:00:28
问题 I'm a bit confused about ARC behaviour when setting variable that is an input pointer, and is expected to remain valid outside function scope. considering the following example that uses openDirectory framework. @interface bbb -(bool)doSomethingWithADRecord: -(void)obtainADRecord(NSString*)user -(NSString*)getADrecord:(ODAttributeType)attr fromRecord:(ODRecord*)record; @end @interface bbb { ODRecord *_myRecord; } @end @implementation bbb -(void)doSomethingWithADRecord: { // here we access

Does the standard mandate an lvalue-to-rvalue conversion of the pointer variable when applying indirection?

我的未来我决定 提交于 2019-12-17 09:52:11
问题 TL;DR Given the following code: int* ptr; *ptr = 0; does *ptr require an lvalue-to-rvalue conversion of ptr before applying indirection? The standard covers the topic of lvalue-to-rvalue in many places but does not seem to specify enough information to determine whether the * operator require such a conversion. Details The lvalue-to-rvalue conversion is covered in N3485 in section 4.1 Lvalue-to-rvalue conversion paragraph 1 and says ( emphasis mine going forward ): A glvalue (3.10) of a non

Assign to a bash array variable indirectly, by dynamically constructed variable name

笑着哭i 提交于 2019-12-17 06:49:11
问题 Bash script to create multiple arrays from csv with unknown columns. I am trying to write a script to compare two csv files with similar columns. I need it to locate the matching column from the other csv and compare any differences. The kicker is I would like the script to be dynamic to allow any number of columns to be entered and it still be able to function. I thought I had a good plan to solve this but turns out I'm running into syntax errors. Here is a sample of a csv I need to compare.

Weird Pointer issue in C++

99封情书 提交于 2019-12-13 22:17:45
问题 I'm running into a VERY frustrating pointer issue. I previously posted here: TOUGH: Dealing with deeply nested pointers in C++ But that post got overly long and is stale, so I chose to repost with more details. Here is my header file that defines my types: #include <string> #include <vector> #include <sstream> #include <iostream> #define USE_3D_GEOM //#define USE_2D GEOM #define DEBUG #ifdef USE_3D_GEOM #define DIMENSIONS 3 #elif USE_2D_GEOM #define DIMENSIONS 2 #else #define DIMENSIONS 1

iterator Overload Member Selection vs Indirection Operator

北慕城南 提交于 2019-12-13 04:43:56
问题 So in the interest of creating a Minimal. Complete, Verifiable Example I have created a toy iterator here (I know it's not perfect, it's just for the purposes of asking a question): class foo : public iterator<input_iterator_tag, string> { string _foo; static const size_t _size = 13; public: const string& operator*() { return _foo; } const foo& operator++() { _foo += '*'; return *this; } const foo operator++(int) { auto result = *this; _foo += '*'; return result; } bool operator==(const foo&

Monitor image access AND/OR prevent direct access

孤人 提交于 2019-12-11 14:15:36
问题 I want users to see an image as part of a web page but I want to avoid them accessing a image directly. This could, say, give clues in the URL about what user they're linked to (a flaw I've seen in one facebook application). How can I go about monitoring image access and/or preventing direct access to images (through url rewriting for example...)? Solutions suggested so far: Use of headers (reliable?) Making access to images more difficult (ex: set image as div background). ... 回答1: There is

Why is my multi-dimensional dynamic allocation in C not working?

倖福魔咒の 提交于 2019-12-11 03:49:07
问题 I have been trying to figure out the problem with my allocation and use of a multidimensional dynamically allocated array in C. I'd really appreciate any help. I've tried two approaches. The first: cdr = (double ***) malloc(NUM_REGIONS * sizeof(double **)); for(i=0; i<NUM_REGIONS; i++){ cdr[i] = (double **) malloc(numRatings * sizeof(double *)); for(j=0; j<numRatings; j++){ cdr[i][j] = (double *) malloc(remQuarters * sizeof(double)); } } And the second: tempPtr1 = (double *) malloc(NUM

Indirection without using eval

家住魔仙堡 提交于 2019-12-11 00:27:37
问题 I'm looking for a clean way (without eval command) to do an indirect reference to an array. Here is a more precise description of what I want : function valueof { echo "indirection1 \$$1=${!1}" eval "echo indirection2 \\\$$1=\${$1[@]}" # Untill this step its fine. # My final objective is to do this (but eval is not a very sexy solution) : for i in $(eval "echo \${$1[@]}") ; do echo $i done # Here is the "problem", ie. "bad substitution" echo "indirection3 \$$1=${!1[@]}" # "1[@]" is evaluated

TOUGH: Dealing with deeply nested pointers in C++

点点圈 提交于 2019-12-08 08:09:44
问题 I define this structure: struct s_molecule { std::string res_name; std::vector<t_particle> my_particles; std::vector<t_bond> my_bonds; std::vector<t_angle> my_angles; std::vector<t_dihedral> my_dihedrals; s_molecule& operator=(const s_molecule &to_assign) { res_name = to_assign.res_name; my_particles = to_assign.my_particles; my_bonds = to_assign.my_bonds; my_angles = to_assign.my_angles; my_dihedrals = to_assign.my_dihedrals; return *this; } }; and these structures: typedef struct s_particle