Remapping of arrays on structs (code style) I'm working on a piece of code that remaps a set of signals (1-D integer arrays) onto a set of multi channel samples. I hope the typedefs and the remapping clearifies what I mean. If not, please let me know.
#include &lt;stdint.h&gt;

#define SIGNAL_LENGTH 1024


/**
* Multiple linear input signals as read by a previous input stage 
*/
typedef struct {
    // Mics inside
    int32_t micInside0[SIGNAL_LENGTH];
    int32_t micInside1[SIGNAL_LENGTH];
    int32_t micInside2[SIGNAL_LENGTH];
    int32_t micInside3[SIGNAL_LENGTH];
    // Mics aux
    int32_t micAux0[SIGNAL_LENGTH];
    int32_t micAux1[SIGNAL_LENGTH];
    int32_t micAux2[SIGNAL_LENGTH];
    int32_t micAux3[SIGNAL_LENGTH];
} InputSignals_t;


/**
* Single input struct to be passed to the following filtering stage 
*/
typedef struct {
    // Mic inside 0
    int32_t micInside0a;
    int32_t micInside0b;
    int32_t micInside0Select;
    // Mic inside 1
    int32_t micInside1a;
    int32_t micInside1b;
    int32_t micInside1Select;
    // Mic inside 2
    int32_t micInside2a;
    int32_t micInside2b;
    int32_t micInside2Select;
    // Mic inside 3
    int32_t micInside3a;
    int32_t micInside3b;
    int32_t micInside3Select;
} FilterSample_t;

/**
* Map the linear input signals to interleved multi-channel filter input signals. 
*/
void mapMicFilters(InputSignals_t *inputSignals, FilterSample_t filterSamples[SIGNAL_LENGTH]) {
    for(int i = 0; i &lt; SIGNAL_LENGTH; i++) {
        FilterSample_t *filterSample = &amp;filterSamples[i];
        
        // I am rather unhappy with the look of the following 
        // code section where the mapping is done.
        
        // Mic inside 0
        filterSample-&gt;micInside0a = inputSignals-&gt;micInside0[i];
        filterSample-&gt;micInside0b = 0;
        filterSample-&gt;micInside0Select = 1;

        // Mic inside 1
        filterSample-&gt;micInside1a = inputSignals-&gt;micInside0[i];
        filterSample-&gt;micInside1b = 0;
        filterSample-&gt;micInside1Select = 1;

        // Mic inside 2
        filterSample-&gt;micInside2a = inputSignals-&gt;micInside0[i];
        filterSample-&gt;micInside2b = 0;
        filterSample-&gt;micInside2Select = 1;

        // Mic inside 3
        filterSample-&gt;micInside3a = inputSignals-&gt;micInside0[i];
        filterSample-&gt;micInside3b = 0;
        filterSample-&gt;micInside3Select = 1;
    }
}

I am rather unhappy with the look of the code section where the mapping is done.The reason for this is that the lines become very long when the signal names become more specific (therefore longer). But a line break within the statements would really mess up the readability:
filterSample-&gt;micInside0a = 
    inputSignals-&gt;micInside0[i];
filterSample-&gt;micInside0b = 
    0;
filterSample-&gt;micInside0Select = 
    1; 

Do you have any suggestions on how to format the code? In dynamic languages I would just take a hashmap with the variable names and loop through it. But I have (and want) to use C.
Thank you!
Whenever I see (e.g.):
int foo0, foo1, foo2, foo3, ..., fooN;

I think that can be replaced more cleanly with an array. So, I'd rather have:
int foo[N];

Thus, I'd change:
int32_t micInside0[SIGNAL_LENGTH];

(et. al.) into:
int32_t micInside[4][SIGNAL_LENGTH];

That sort of thing occurs in several more places for different variables as well.

A good style rule is to use shorter names for argument names and stack/automatic variables [that have shorter scope/duration] and longer names for globals.
For example: FilterSample_t filterSamples[SIGNAL_LENGTH] is a bit redundant and could be shortened to (e.g.) FilterSample_t fslist[SIGNAL_LENGTH]
Likewise, FilterSample_t *filterSample = &amp;filterSamples[i]; is a bit long and could be shortened to: FilterSample_t *fscur = &amp;fslist[i];
To me, the longer names are &quot;too much eye candy&quot;.
Also, with the shorter names, the lines will be shorter, so they're less likely to need to be wrapped to multiple lines [with the indenting].

If you add an additional struct, you can reorganize/simplify micInside* and micAux*.

As to the indenting of the second [wrapped] line that you didn't like, personally, I do that 10 times / day. I've found that to be very clean. But, I've been doing that for 20+ years, so I'm used to it.

Note that you did [for all &quot;X&quot;, where &quot;X&quot; is one of 0,1,2,3]:
filterSample-&gt;micInsideXa = inputSignals-&gt;micInside0[i];

But, I think that was a typo and you meant to do:
filterSample-&gt;micInsideXa = inputSignals-&gt;micInsideX[i];


I realize that school classes teach the use of i, j, etc. But, I've found that more descriptive names can make the code clearer.

Anyway, I've refactored your code incorporating these ideas.
Caveat: I had some difficulty with the remapping to arrays and I had to guess a bit about some of the relationships. (e.g.) CHANMAX for &quot;max # of channels&quot; was a guess, based on my experience with video and audio processing and seeing &quot;mic&quot; (as in &quot;microphone&quot;) and &quot;aux&quot; (as in &quot;auxiliary audio&quot;).
And I may have messed this up by transposing the array indexes, but it should give you an idea of what I'm driving at:
#include &lt;stdint.h&gt;

#define SIGNAL_LENGTH 1024

#define CHANMAX     4

/**
* Multiple linear input signals as read by a previous input stage
*/
typedef struct {
    // Mics inside
    int32_t micInside[CHANMAX][SIGNAL_LENGTH];

    // Mics aux
    int32_t micAux[CHANMAX][SIGNAL_LENGTH];
} InputSignals_t;

typedef struct {
    int32_t mic_a;
    int32_t mic_b;
    int32_t mic_select;
} micfilter_t;

/**
* Single input struct to be passed to the following filtering stage
*/
typedef struct {
    micfilter_t filt_micinside[CHANMAX];
} FilterSample_t;

/**
* Map the linear input signals to interleved multi-channel filter input signals.
*/
void
mapMicFilters(InputSignals_t *inputSignals, FilterSample_t fslist[SIGNAL_LENGTH])
{
    for (int isamp = 0; isamp &lt; SIGNAL_LENGTH; isamp++) {
        FilterSample_t *fscur = &amp;fslist[isamp];
        InputSignals_t *inpbase = &amp;inputSignals[isamp];

        // I am rather unhappy with the look of the following
        // code section where the mapping is done.

        for (int ichan = 0;  ichan &lt; CHANMAX;  ++ichan) {
            micfilter_t *fchan = &amp;fscur-&gt;filt_micinside[ichan];
            int32_t *inpcur = inpbase-&gt;micInside[ichan];
            fchan-&gt;mic_a = inpcur[isamp];
            fchan-&gt;mic_b = 0;
            fchan-&gt;mic_select = 0;
        }
    }
}