- May 11, 2008
- 21,688
- 1,297
- 126
I have a question about when to use a dot . operator or arrow -> operator.
And why gcc gives an error.
I have an array declared.
And in a function i make use of that array.
This code works but since i have some variables and arrays i decided to put them in a struct to clean up the code.
I made a struct :
This compiles :
But this does not :
Why does gcc 4.7.2 not compile this ?
It stops with error :
What am i not understanding about the difference between an dot operator and an arrow operator?
I googled for it, but i do not want examples on how to use it, i want to understand what the differences are and when to use either properly.
I am just a hobby programmer, it is not my profession.
And why gcc gives an error.
I have an array declared.
And in a function i make use of that array.
This code works but since i have some variables and arrays i decided to put them in a struct to clean up the code.
Code:
int16_t ssc_audio_buffer1[AUDIOBUFFER_SIZE];
[B]code : snippet of function :[/B]
pointer = (uint8_t *)ssc_audio_buffer1;
fr = f_read(&file,pointer, sizeof ssc_audio_buffer1, &bytesread);
if(bytesread == 0)
{
Stop_Song();
}
I made a struct :
Code:
#define AUDIOBUFFER_SIZE 1024
typedef struct
{
uint8_t ssc_dma_flag;
uint8_t ssc_dma_option_flag;
uint8_t dmabuffer_select_flag;
uint8_t ssc_pause_flag;
int16_t ssc_audio_buffer1[AUDIOBUFFER_SIZE];
int16_t ssc_audio_buffer2[AUDIOBUFFER_SIZE];
} audio_struct_t;
This compiles :
Code:
pointer = (uint8_t *)audio_ctrl.ssc_audio_buffer1;
fr = f_read(&file,pointer, sizeof audio_ctrl.ssc_audio_buffer1, &bytesread);
if(bytesread == 0)
{
Stop_Song();
}
But this does not :
Code:
audio_ctrl.dmabuffer_select_flag = 1;
pointer = (uint8_t *)audio_ctrl->ssc_audio_buffer1;
fr = f_read(&file,pointer, sizeof audio_ctrl->ssc_audio_buffer1, &bytesread);
if(bytesread == 0)
{
Stop_Song();
}
Why does gcc 4.7.2 not compile this ?
It stops with error :
src/ssc.c: In function 'UpdateDmaBuffers':
src/ssc.c:75:35: error: invalid type argument of '->' (have 'audio_struct_t')
src/ssc.c:76:48: error: invalid type argument of '->' (have 'audio_struct_t')
What am i not understanding about the difference between an dot operator and an arrow operator?
I googled for it, but i do not want examples on how to use it, i want to understand what the differences are and when to use either properly.
I am just a hobby programmer, it is not my profession.