Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I am trying to write a floppy driver, and I have come accross a problem. I am trying to memcpy the disk parameters from their location in the memory, but I get a parse error when I try to compile it. Here's the code:
#define DISK_PARAMETER_ADDRESS 0x000fefc7
//location where disk parameters are stored by bios
typedef struct{
unsigned char steprate_headunload;
unsigned char headload_ndma;
unsigned char motor_delay_off; /*specified in clock ticks*/
unsigned char bytes_per_sector;
unsigned char sectors_per_track;
unsigned char gap_length;
unsigned char data_length; /*used only when bytes per sector == 0*/
unsigned char format_gap_length;
unsigned char filler;
unsigned char head_settle_time; /*specified in milliseconds*/
unsigned char motor_start_time; /*specified in 1/8 seconds*/
}floppy_parameters;
floppy_parameters floppy_disk; //declare variable of floppy_parameters type
memcpy(&floppy_disk, (unsigned char *)DISK_PARAMETER_ADDRESS, sizeof(floppy_parameters));
// Copy parameters (doesn't work)
I have tried many variations, but I still can't get it to compile... If I comment out the last line, it does compile, but then the driver won't work... The error is:
and actually, that sounds weird to me to have memcpy(...) in a .h file, at top level. that line should be part of your main() function, not as a standalone declaration
I have tried many variations, but I still can't get it to compile... If I comment out the last line, it does compile, but then the driver won't work... The error is:
In file included from floppy.c:4:
include/floppy.h:26: error: parse error before '&' token
I may be wrong, but I think this is crystal clear: you're writing code outsite a function! C is no scripting language, dude, the only thing you can write at the global scope is definitions (of functions, variables, structs)... You are calling memcpy from the global scope, which does not work because the compiler won't know where to put that code.
Make up your mind and think where that code should go (first of all: NOT in a .h file - header files are for definitions, not code). If you are sure that the best place would be the global scope - because it performs some type of disk driver initialization - bad luck, because there is no global scope: put it into some disk_driver_initialize() function and make sure it gets called before other disk driver functions.
Have a good OS developing time!
Edit: D'oh! I'm late... Pype has already pointed this out
Sorry, that was a reply to Kemp's post. I read the post, messed around with my code for 10 minutes, and then hit reply. I didn't realise that two other people had posted in that time!
Putting the memcpy in the init function worked ;D . The reason it was in the header was because I cleaned up my c file by copying the parameters structure and a bunch of defines into the header, and that memcpy was in the middle of it all...