![]() |
| | #1 |
| Registered User Join Date: Feb 2006 Location: Ballincollig, co. cork, Eire
Posts: 19
| Help with a Struct problem Just need a bit of advice on some C++ related issues. I have the following: Code: #include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <windows.h>
#include "et1000.h"
#pragma comment( lib, "smbw32vc.lib" )
using namespace std;
//prototypes
// h = Hub, s = Slot, p = Port
void setTxParams (int h, int s, int p);
int main()
{
//Set Hub, Slot and Ports to be used.
int h1 = 0;
int s1 = 0;
int p1 = 0;
int h2 = 0;
int s2 = 0;
int p2 = 1;
unlink();
return 0;
}
void setTxParams (int h, int s, int p)
{
CHECKERROR(HTSetStructure(ETH_TRANSMIT, 0, 0, 0,
(void*) pETHTransmit, sizeof(ETHTransmit), h, s, p));
}
typedef struct tagETHTransmit
{
unsigned char ucTransmitMode; /* transmit mode:
CONTINUOUS_PACKET_MODE
SINGLE_BURST_MODE
MULTI_BURST_MODE
CONTINUOUS_BURST_MODE
ECHO_MODE */
unsigned short uiDataLength; /* number of bytes per frame, not
including 4 byte CRC */
} ETHTransmit;
Is it ok to put the struct at the end of the code, like above? If not, where should I put it? I have a lot of parameters that need to be specified to set up the transmit parameters. void setTxParams points to the struct. So, where do I set the values for the struct parameters? In int main() like this: Code: ETHTransmit.ucTransmitMode = SINGLE_BURST_MODE; Code: void setTxParams (int h, int s, int p)
{
ETHTransmit.ucTransmitMode = SINGLE_BURST_MODE;
CHECKERROR(HTSetStructure(ETH_TRANSMIT, 0, 0, 0,
(void*) pETHTransmit, sizeof(ETHTransmit), h, s, p));
}
Finally, is there anything more I may need to do that I may have left out? Regards Brownie //Using Microsoft Visual C++ Express 2008 on a Windows XP machine |
| Brownie is offline | |
| | #2 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,364
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #3 | |
| Wheres the lesbians? Join Date: Oct 2006 Location: UK
Posts: 1,219
| Quote:
AFAIK the declaration does not create a struct it simply defines the stucture and the way its laid out so each time that you want to create an instance of ETHTransmit you will need to declare it as: Code: ETHTransmit instanceName; Code: instanceName.ucTransmitMode = SINGLE_BURST_MODE;
__________________ Senior highbrow doctor of authority. Last edited by mike_g; 10-01-2008 at 05:15 AM. | |
| mike_g is offline | |
| | #4 | |
| Banned Join Date: Aug 2001 Location: Visalia, CA, USA
Posts: 3,699
| Ok, here is an analogous situation. Brownie lets pretend like we are mechanics for my hypothetical. Quote:
Does that make sense? I could argue that a compiler could be written to preprocess an entire project and scan for all formal class and structure definitions prior to trying to build. But C/C++ do not do that, and its a simple rule to follow. If programming were about wishful thinking, I wish my compiler would automatically build a production build whenever there were no bugs. And if there are bugs, I wish it would automatically place breakpoints immediately before them. | |
| master5001 is offline | |
![]() |
| Tags |
| struct |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Struct File and array problem Please help | theprogrammer | C Programming | 17 | 04-02-2009 08:05 AM |
| memory issue | t014y | C Programming | 2 | 02-21-2009 12:37 AM |
| Link List math | t014y | C Programming | 17 | 02-20-2009 06:55 PM |
| problem with reading struct from file generated by hexdump | wollek | C Programming | 22 | 12-23-2008 01:53 PM |
| Converting a circulating mouse pointer to use a Potentionmeter | phoenix23 | C Programming | 16 | 10-29-2006 05:04 AM |