Questions tagged [indirection]

Any of various programming concepts related to the level of abstraction applied to a particular problem, algorithm or scenario. Examples may include substituting higher-level programming constructs where previously lower-level constructs were previously applied.

Indirection

Any of various programming concepts related to the level of abstraction applied to a particular problem, circumstance, algorithm or knowledge domain.

160 questions
114
votes
6 answers

What is indirect expansion? What does ${!var*} mean?

I'm reading "Bash Guide for Beginners". It says: If the first character of PARAMETER is an exclamation point, Bash uses the value of the variable formed from the rest of PARAMETER as the name of the variable; this variable is then expanded and…
athos
  • 6,120
  • 5
  • 51
  • 95
93
votes
4 answers

Use placeholders in YAML

Is there a way to use placeholders in YAML like this: foo: &FOO <>: type: number default: <> bar: - *FOO propname: "some_prop" default: "some default"
88
votes
3 answers

Dynamic constant name in PHP

I am trying to create a constant name dynamically and then get at the value. define( CONSTANT_1 , "Some value" ) ; // try to use it dynamically ... $constant_number = 1 ; $constant_name = ("CONSTANT_" . $constant_number) ; // try to assign the…
vikmalhotra
  • 9,981
  • 20
  • 97
  • 137
49
votes
7 answers

What does the quote "An extra level of indirection solves every problem" mean?

What does the quote "Level of Indirection solves every Problem" mean in Computer Science?
Vicky
  • 11,077
  • 11
  • 35
  • 29
45
votes
3 answers

What does "level of indirection" mean in David Wheeler's aphorism?

I've read this quote in a book: There is no problem in computer science that can't be solved using another level of indirection. Can someone explain that? What does "level of indirection" mean? From what I understood, indirection is a fancy…
Andrei Diaconu
  • 601
  • 2
  • 8
  • 15
39
votes
7 answers

How to iterate over an array using indirect reference?

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 "[@]"…
Neuquino
  • 11,580
  • 20
  • 62
  • 76
29
votes
1 answer

What does the UNPACK pragma do, in this case?

I have trouble understanding how UNPACK works in Haskell. Consider, for example, the following data declarations: data P a b = P !a !b data T = T {-# UNPACK #-} !(P Int Int) How will datatype T be unpacked? Will it be equivalent to data T' = T'…
Alexey Vagarenko
  • 1,206
  • 8
  • 15
26
votes
8 answers

Is there a convention for pointer declarations in C?

When declaring pointers in C, there are 3 variants: Variant A: int* ptr; Variant B: int *ptr; Variant C: int * ptr; In A, the indirection operator has been appended to the type. In B, the indirection operator has been prepended to the…
schmittsfn
  • 1,412
  • 18
  • 40
25
votes
2 answers

Does the C preprocessor remove instances of "&*"?

I was playing around with gcc and tried the following bit of code: int A = 42; int *B = &A; int *C = &*B; And C == &A, as expected. But when I try: int *B = NULL; int *C = &*B; Turns out C == NULL, and no segfault. So &*B is not actually…
evenex_code
  • 843
  • 1
  • 8
  • 20
19
votes
2 answers

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

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…
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
13
votes
2 answers

Does C++ Standard description of indirection operator guarantee memory writes are not optimized away?

This is basically a continuation of this question. So far it looks like that if I have a function like this: void SecureZeroMemory( void* ptr, size_t cnt ) { volatile char *vptr = (volatile char *)ptr; while (cnt) { *vptr = 0; …
12
votes
2 answers

Scalar value being affected after push, or not... (Raku)

I have difficulty understanding when and why the value held by a pushed Scalar container is affected after the push. I'll try to illustrate the issue that I ran into in a more complicated context in two stylized examples. *Example 1 * In the first…
ozzy
  • 785
  • 3
  • 12
11
votes
2 answers

How to overload the indirection operator? (C++)

I'm trying to create an iterator class as a member-class for a list class, and am trying to overload the indirection operator (*) to access the list it's pointing to: template T list::iterator::operator*(iterator& iter) { return…
user98188
9
votes
1 answer

Making a nameref a regular variable in bash

EDIT: This has been confirmed to be a bug and will be fixed: https://lists.gnu.org/archive/html/bug-bash/2018-03/msg00055.html So I'm messing around with bash's indirection feature, namerefs. I thought I had gotten the hang of it, but then I hit…
greatBigDot
  • 505
  • 3
  • 9
8
votes
3 answers

Javascript - set a variable using concatenation of strings

Is it possible to set a variable by concatenating two strings together to form the name? If at all possible I'd like to determine what variable to set based on the class names of the objects that the user clicks. I know I can hard code a bunch of…
Chris Schmitz
  • 20,160
  • 30
  • 81
  • 137
1
2 3
10 11