+1  A: 

Another try:

void applyThingy(int *grid, int xPitch, int yPitch)
{
    int row, column;
    int *rowPointer = grid;

    for(row = 0; row < 3; ++row)
    {
        int *columnPointer = rowPointer;

        for(column = 0; column < 3; ++column)
        {
            doOperation(columnPointer);
            columnPointer += xPitch;
        }

        rowPointer += yPitch * 9;
    }
}

applyThingy(&grid[SUB(n)], 1, 1); // Perform on 3x3 subgrid
applyThingy(&grid[ROW(n)], 1, 0); // Perform on row
applyThingy(&grid[COL(n)], 0, 1); // Perform on column
strager
Ah, not exactly. If I am working on column 0, index 0, I would grab (also) the next two down in that column (which happen to have the indexes 9 and then 18) and perform said operation on them. Repeat this for the next three, etc, and cont. for each column and submatrix.
Sid McAwesome
@Sid, So you want to perform one common operation for each column, row, and 3x3 sudoku grid?
strager
@Sid, Are you limited to pure C or can C++ be used?
strager
Pure C is prefered, but if I can benefit from C++, I'd like to be shown.
Sid McAwesome
@strager - On the second comment you are pretty much right.
Sid McAwesome
@Sid, Then look at my updated answer. Or is this not what you want?
strager
WOOT, SOLVED. Any type of rep I can give you?
Sid McAwesome
A: 

I'm not sure what you want to do, but is it something like this?:

#define IDX(row, col) ((row)*9+(col))

int m = some_column;
for (int n = 0; n < 9; n += 3) {
  a = grid[IDX(n, m)];
  b = grid[IDX(n+1, m)];
  c = grid[IDX(n+2, m)];
  r = ...;
  ...
}

Also, I'm not sure what you want to do with your operation

r = ((a = ~a) & (b = ~b)) | ((b | a) & ~c);

You're assigning ~a to a, is that what you want? How is a defined, and what are you trying to set it to? What are you trying to achieve?

sth
It's simply to avoid having to perform another not operation later. Not sure if it helps. I'm close to giving up on this problem and trying a different solution.
Sid McAwesome
Although yours might be what I need.
Sid McAwesome
Gah, hate to post so many comments, but would you have a way to perform that operation on rows and my 'submatrixes'?
Sid McAwesome
I see... But I think the speedup of this optimization is neglectable, ~(...) is a very fast operation. Also: are you sure the operands are evaluated from left to right? I don't think this is guaranteed. Better stick to the second version, there is still time for improvements once everything works.
sth
You could just calculate the row numbers in the "main" matrix? If for example your submatrix starts at row 3, it's rows would be at 3+0, 3+1 and 3+2 in the main matrix. Then just access the main matrix at those rows. (The same for columns: If the submatrix starts at 6, the cols are 6+0, 6+1 and 6+2)
sth