Hi,
I wrote a trivial program to test the stack-gap feature under openbsd
4.0 i386.
There's something I can't get about the output of that software, and
maybe someone can help me shed some light on it.

Here's the program:
----8<---
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

# define FIRST          400
# define SECOND         400
# define THIRD          400
# define FOURTH         400
# define LAST           FOURTH
# define last           fourth
# define NUMOFVEC       4

void stackgap( int * pointer );

int main( void )
{
    // This is here as a placeholder
    int a = 129;
    stackgap( &a );
    return EXIT_SUCCESS;
}

void stackgap( int * pointer ) {

    char first[FIRST];
    char second[SECOND];
    char third[THIRD];
    char fourth[FOURTH];

    printf("\n\n***********************************************************\n");
    printf("*                       STACK GAP                         *");
    printf("\n***********************************************************\n\n");

    printf("Distance between the only variable in main and the first vector is: 
%ld bytes \n\n",(long) pointer - (long) first);
}
----8<---

Obviously address of vectors change every execution, and that's ok, but
distance between variable "a" and vector first varies between 460 and
472 bytes. Shouldn't it be fixed? Why does this happens? I tought stack
gap couldn't influence relative placement of variables in stack frames.

Thanks in advance,
Gufo

Reply via email to