M
Mark
I'm somewaht confused with what type to choose and possible conversion it
may have to undergo. Let me explain with a real example:
extern int read_reg(int unit, unsigned int addr, uint16_t *val);
....
#define REG_PORT 0x50
/* ports enumerate from 1 to 25 */
extern int port_link_get(int unit, unsigned short port, int *link);
int port_link_get(int unit, unsigned short port, int *link)
{
int rv;
unsigned short addr;
uint16_t val;
addr = REG_PORT + ((port - 1) / 3);
rv = read_reg(unit, addr, &val);
....
return rv;
}
As far as I know, only in the absence of a prototype, function arguments
unfergo default promotions. We have prototypes, so no promotion/conversion
apply to arguments, am I tight?
Furthemore, the second argument of 'port_link_get' is of type 'unsigned
short', it participates in evaluating 'addr'. Will the operands of 'addr =
...' undergo arithmetic conversion?
And finally 'addr' is passed to 'read_reg', where it should be converted
(promoted?) to uint32_t. If so, it'd probably more effective to have:
extern int port_link_get(int unit, unsigned int port, int *link);
Are my reasonings right?
So, if I'm on an embedded system with memory constrints, it would not be
possible to save a few bytes by declaring 'port' argument as unsigned short
or even unsigned char?
What is the common sense to decide on data type, so for both effective use
and portable?
may have to undergo. Let me explain with a real example:
extern int read_reg(int unit, unsigned int addr, uint16_t *val);
....
#define REG_PORT 0x50
/* ports enumerate from 1 to 25 */
extern int port_link_get(int unit, unsigned short port, int *link);
int port_link_get(int unit, unsigned short port, int *link)
{
int rv;
unsigned short addr;
uint16_t val;
addr = REG_PORT + ((port - 1) / 3);
rv = read_reg(unit, addr, &val);
....
return rv;
}
As far as I know, only in the absence of a prototype, function arguments
unfergo default promotions. We have prototypes, so no promotion/conversion
apply to arguments, am I tight?
Furthemore, the second argument of 'port_link_get' is of type 'unsigned
short', it participates in evaluating 'addr'. Will the operands of 'addr =
...' undergo arithmetic conversion?
And finally 'addr' is passed to 'read_reg', where it should be converted
(promoted?) to uint32_t. If so, it'd probably more effective to have:
extern int port_link_get(int unit, unsigned int port, int *link);
Are my reasonings right?
So, if I'm on an embedded system with memory constrints, it would not be
possible to save a few bytes by declaring 'port' argument as unsigned short
or even unsigned char?
What is the common sense to decide on data type, so for both effective use
and portable?