| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Basic C syntax |
> What is wrong with msg_receive? Suggest a fix.
> #define MAXVALS 65536
> typedef struct _msg_t {
> unsigned int num;
> unsigned int values[MAXVALS];
> } msg_t;
> int msg_receive(int fd, msg_t *m)
> {
> size_t sz = sizeof(unsigned int);
> assert(m);
> if( read(fd, (void *)&m->num, sz) < sz)
> return -1;
> return read(fd, (void *)&m->values, sz * m->num);
> }
Answer: It has a typo on _msg_t. That's why it won't work.
Given that m is a pointer to a structure of type _msg_t or msg_t (the
code is not clear whether the underline is there or not), m->num or
m->values is required, rather than &m->etc.
Fix: decide whether the initial underline is needed. 2) Use the pointer
rather than the address of the pointer.
Best Wishes,
Bill.
---
* Origin: Escan BBS (2:25/200)SEEN-BY: 633/267 270 @PATH: 25/200 108 252/110 250/501 140/1 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.