Not sure how the core you are using is done, but one option is to mask off the reference bits (they are in the ADMUX register), and place the result into a tempory variable. Then "or" the desired reference bits with the tempory variable (local_ADMUX) and save that back into the ADMUX register.
void analogReference(uint8_t reference)
{
analog_reference = reference;
#if defined(ADMUX)
// clear the reference bits REFS0, REFS1[,REFS2]
uint8_t local_ADMUX = (ADMUX & ~(ADREFSMASK));
// select the reference so it has time to stabalize.
ADMUX = local_ADMUX | reference ;
#else
# error missing ADMUX register which is used to sellect the reference and channel
#endif
}
The number six might be like this INTERNAL_2V56WOBP define, but without the bit shifting stuff I added for reference.
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
#define ADREFSMASK (1<<REFS2) | (1<<REFS1) | (1<<REFS0)
#define EXTERNAL_AVCC 0
#define EXTERNAL_AREF (1<<REFS0)
#define INTERNAL_1V1 (1<<REFS1)
#define INTERNAL_2V56WOBP (1<<REFS2) | (1<<REFS1)
#define INTERNAL_2V56 (1<<REFS2) | (1<<REFS1) | (1<<REFS0)
#endif