I'm working in C and getting the following error:
*** ERROR C074 IN LINE 78 OF ..\..\..\libraries\mchpstack_base\arp.c : Invalid declaration syntax
The relevant portion of code is:
typedef struct _ARP_PACKET
{
WORD HardwareType;
WORD Protocol;
BYTE MACAddrLen;
BYTE ProtocolLen;
WORD Operation;
MAC_ADDR2 SenderMACAddr;
IP_ADDR SenderIPAddr;
MAC_ADDR2 TargetMACAddr; // This is line 78
IP_ADDR TargetIPAddr;
} ARP_PACKET;
Now MAC_ADDR2 is define elsewhere in a header file which I am sure is included in arp.c:
typedef struct _MAC_ADDR2
{
BYTE v[6];
} MAC_ADDR2;
I'm new to C; but read over guides on creating structs, the typedef usage, and the namespace issue within C. I'm quite stuck. What is that error telling me?
Related
I have what I feel is a very basic issue but for some reason I can't seem to resolve it. I am getting the following errors:
drivers/cpufreq/AI_gov.h:37:2: error: unknown type name 'phase_state'
drivers/cpufreq/AI_gov.h:38:2: error: unknown type name 'phase_state'
now in my file AI_gov_phases.h I have the following typdef enum:
typedef enum{
response,
animation,
idle,
load
} phase_state;
now in the file that is throwing the error AI_gov.h I have:
#include "AI_gov_phases.h"
....
struct AI_gov_info{
struct AI_gov_cur_HW* hardware;
struct AI_gov_profile* profile;
phase_state phase;
phase_state prev_phase;
};
typedef enums are definitely one of my weaker areas so any help would be appreciated.
I am following LDD3 for learning network device driver. I just compiled the source code of snull driver and I got this compilation error:
error: ‘struct net_device’ has no member named ‘open’
I also got similar error when I try to initialize other members of struct net_device. Please help to resolve this error.
Below is the code:
struct net_device *snull_devs[2];
snull_devs[0] = alloc_netdev(sizeof(struct snull_priv), "sn%d",
snull_init);
void snull_init(struct net_device *dev)
{
ether_setup(dev); /* assign some of the fields */
dev->open = snull_open;
dev->stop = snull_release;
That book is pretty old, and this has apparently changed in more recent kernels. struct net_device now has the following member:
const struct net_device_ops *netdev_ops;
This has members like:
int (*ndo_open)(struct net_device *dev);
int (*ndo_stop)(struct net_device *dev);
So the equivalent code would be:
dev->netdev_ops->ndo_open = snull_open;
dev->netdev_ops->ndo_stop = snull_release;
But there could be other changes to the device driver environment that affect how this should be coded. I suggest you read the chapter API changes in the 2.6 kernel series.
Before I continue, here is the code which is giving me an error:
#define numScores 3 // the number of test scores which a student will have
struct btreenode{
int studentID; // the ID number of the student at the current node
float scores[3]; // the 3 test scores of the student
float average; // the average of the 3 test scores for the student
struct btreenode *left; // pointer to left side of the tree
struct btreenode *right; // pointer to right side of the tree
};
typedef struct btreenode *Node;
I'm getting the following error when I compile:
btreenode.h:17: error: redefinition of 'struct btreenode'
btreenode.h:28: error: conflicting types for 'Node'
btreenode.h:28: note: previous declaration of 'Node' was here
I have a block comment at the top so the line numbers are off, but
line 17 is the first line "struct btreenode{"
line 28 is the last line "typedef struct btreenode *Node"
Does anyone know why i'm getting these errors?
The header file should not be included more than once. So use macro in header file to avoid multiple inclusion.
#ifndef TEST_H__
#define TEST_H__
/*you header file can have declarations here*/
#endif /* TEST_H__*/
I am assumed that, this kind of approach is not there in your header file.
It looks as though your btreenode.h file is being included (directly or indirectly) multiple times... that's why the "previous declaration" and the "conflicting types" are in the same file at the same line (previous declaration on the first include, conflicting types when it runs into the same line on the next include).
You should use header guards (in btreenode.h) to prevent the header file code from being processed if it's already been included. At the top of the file, add:
#ifndef BTREENODE_H
#define BTREENODE_H
and at the end of the file add:
#endif // BTREENODE_H
That way, whatever is between those will only be compiled if BTREENODE_H was not already #defined from a previous inclusion.
I'm using libwebsockets and I can't compile a demo code implemented by myself.
I created the context:
struct libwebsocket_context *context;
...
context = libwebsocket_create_context(&info);
and when I try to access the members of the struct libwebsocket_context, defined in private-libwebsockets.h:
struct libwebsocket_context {
struct pollfd *fds;
struct libwebsocket **lws_lookup; /* fd to wsi */
int fds_count;
int max_fds;
int listen_port;
...
};
For example,
printf("%d\n", context->listen_port);
The compiler returns,
error: dereferencing pointer to incomplete type
Thanks!
It seems that "struct libwebsocket_context" is not known for gcc - that's why this error occures. Are you sure that definition of this structure is included from .h file? I'd suggest you to insert for example #warning or #error with some message near definition of this struct (in .h file) and try to recompile your program. Your #error or #warning message should appear while compilation. If not - it means that gcc will not also see this struct.
The fact that the struct definition is in private-libwebsockets.h suggests that you are not supposed to use the struct members directly. You can #include that header to get access to the private implementation details of the library but you probably should not do it.
Consider the following typedef struct in C:
21:typedef struct source{
22: double ds; //ray step
23: double rx,zx; //source coords
24: double rbox1, rbox2; //the box that limits the range of the rays
25: double freqx; //source frequency
26: int64_t nThetas; //number of launching angles
27: double theta1, thetaN; //first and last launching angle
28:}source_t;
I get the error:
globals.h:21: error: redefinition of 'struct source'
globals.h:28: error: conflicting types for 'source_t'
globals.h:28: note: previous declaration of 'source_t' was here
I've tried using other formats for this definition:
struct source{
...
};
typedef struct source source_t;
and
typedef struct{
...
}source_t;
Which both return the same error.
Why does this happen? it looks perfectly right to me.
Are you sure you didn't include your header twice (without using #ifndef/#pragma once to avoid that)?
Even if there'd been some mistake in your construct it shouldn't trigger the error "redefinition of '...'" cause it's the very first line?
The most likely cause is that your header file is being included more than once.
You need to ensure that if this happens, the typedef is only executed once.
You can do this by wrapping globals.h with:
#ifndef _globals_h_
#define _globals_h_
[...]
#endif
The errors say a struct source has been defined more than once.
Maybe you included the header file twice?
Just to be on the safe side, be sure that your header gets only included once: put
#ifndef YOUR_HEADER_FILE_NAME
#define YOUR_HEADER_FILE_NAME
at the beginning, and
#endif
at the end of your header file: this will prevent it to be included twice or more by any source file.