![]() |
Pointers/References?
:yikes: I'm trying to write a function that reads values from eeprom and stores their values into variables passed into the function. This is what it looks like:
:] Code:
void Terminal_eepromreadset(unsigned char set, unsigned char *data1, unsigned char *data2, unsigned char *data3, unsigned char *data4)For some reason I get the following warnings when I compile: Code:
C:\frc\FrcCode_2007_8722\terminal.c:550:Warning [2054] suspicious pointer conversionAny ideas? |
Re: Pointers/References?
Quote:
Code:
void Terminal_eepromreadset(unsigned char set, unsigned char data[4])Code:
void Terminal_eepromreadset(unsigned char set, unsigned char *data)Quote:
Code:
Terminal_eepromreadset(0, &version1,.....)Code:
unsigned char version[4];Confusing as dirt? :) ttyl, --buddy |
Re: Pointers/References?
Quote:
Is there a way to make the multi-variable-in-the-input idea work? It cleans the code up so much that I would rather keep it that way. Can someone at least tell me why I get that message about a "suspicious pointer conversion"? I'm sure the code would work if I could pass more than just one variable into the function (which is what it seems). |
Re: Pointers/References?
1 Attachment(s)
:yikes: I think I (might) have fixed it. (at least, it's not giving me errors anymore...)
The following is the example in entirety: Code:
// Eepromhelper.cHope this can be helpful to some others |
Re: Pointers/References?
Quote:
Quote:
[quote=htwiz2002;567274] Code:
void Terminal_eepromreadset(unsigned char set, unsigned char *data1, unsigned char *data2, unsigned char *data3, unsigned char *data4)Quote:
Also, why are you using global variables here instead of declaring them inside this function? Also, perhaps you should name your case.... Code:
#define VERSION_SET (0)Quote:
Code:
default:A programmer's job is to write documentation that happens to compile.... :) Suggestions: Use whitespace, it's free. Avoid global variables like the plague. If you must use globals, stick a 'g' in front of the name, again so that you know it's a global. Make all your globals 'static'. This means that they won't conflict with another global in a different file. That can cause huge headaches. ttyl, --buddy |
Re: Pointers/References?
[quote=buddy.smith;567537]I was just suggesting the array method to show the possibility. You can do it the way you were doing it before.... (details below)
What's the -1 for? Why not just set*4, then add 0, 1, 2, 3? Quote:
Anyways, I'll make some major changes.... With the "break" thing I was trying to consolidate things so that I wouldn't need to scroll half a mile just to get from section to section, while (hopefully) improving readability (since most of the code that I combine to one line doesn't need (normally) to be changed or read much. Also, my globals (generally) have the file's name prefixed so as to help prevent them being used (normally, again) outside of the file. Problems do arise when I try to access them o-o-f, but since I moved the handler code i haven't needed to (much). Again, code in beta, far from finished. I was using the version globals for version checking and for the test set. They will become #define s soon enough, as well as many of the other global variables. |
Re: Pointers/References?
No worries.
I personally use vim with some nice things for auto-indenting code. Also, if your functions are so long that they won't fit on one screen, it's a good sign that your function might be too long. But I've digressed far beyond the initial topic. If you require more assisstance, I'll be trolling this forum. I'd love to help any other teams that need it.... :) Another thing you can do, is group the things that will be in your eeprom into a struct: Code:
struct {[code] void eeprom_read(void *pData, unsigned char size) { /* Read data into pData here */ } void test( void ) { eeprom_read( &gEepromStruct, sizeof(gEepromStruct)); } Now your eeprom read/write are generic, and you can put anything you want in the eeprom without changing that code. ttyl, --buddy |
Re: Pointers/References?
Also, you can prevent global variables from being accessed outside of their file by declaring them as static. For example:
In user_routines_fast.c: Code:
static int auto_counter;Code:
extern int auto_counter; /* This will not compile! */ |
| All times are GMT -5. The time now is 17:43. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi