I am doing my project in C and faced the problem of using alignas in VisualStudio
If we believe this example, then I just have to write alignas(16) const uint16_t _decode_table[] = {...}; But errors appear during compilation https://ibb.co/02w8crP
static unsigned table_walk(unsigned cur_idx, unsigned entry_idx, unsigned* out_kind) {
alignas(16) const uint16_t _decode_table[] = {
#define FD_DECODE_TABLE_DATA
#include <fadec-decode-private.inc>
#undef FD_DECODE_TABLE_DATA
};
unsigned entry = _decode_table[cur_idx + entry_idx];
*out_kind = entry & ENTRY_MASK;
return (entry & ~ENTRY_MASK) >> 1;
}
I get this error
error C2143: syntax error: missing ';' before 'const'
error C2065: '_decode_table': undeclared identifier
error C2109: subscript requires array or pointer type
So this is how I can use alignas if I get an error when compiling in Visual Studio?.
Related
I like to know what is HISTOGRAMS in EBPF.
So for example below ebpf program creates histogram
Compiling it cause warning then bunch of errors udp.c:7:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int] BPF_HISTOGRAM(counter, u64);
SO in this tutorial about XDP it tells to create histogram I need to do BPF_HISTOGRAM(counter, u64); so where BPF_HISTOGRAM is #defined. Also what needed to be a type specifier in above waring so if I am doing BPF_HISTOGRAM(counter, u64); so I am assuming it wil be expended to something like u64 counter so if thats the case there here u go I have type specifier than what else is it complaining about in clang command root#fawad:/home/fawad/bpf# clang -I /usr/include/x86_64-linux-gnu/ -O2 -Wall -target bpf -c udp.c -o udp.o
How how to get rid of these errors and a warning if I try to compile with above command
Errors like : IPPROTO_UDP not found
use of undeclared u64
use of undeclared counter,(if I am assuming right in above question text why this warning and error about counter and histogram)
So I have this simple code
#define KBUILD_MODNAME "udp_counter"
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/udp.h>
BPF_HISTOGRAM(counter, u64);
int udp_counter(struct xdp_md *ctx)
{
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
struct ethhdr *eth = data;
if ((void *)eth + sizeof(*eth) <= data_end)
{
struct iphdr *ip = data + sizeof(*eth);
if ((void *)ip + sizeof(*ip) <= data_end)
{
if (ip->protocol == IPPROTO_UDP)
{
struct udphdr *udp = (void *)ip + sizeof(*ip);
if ((void *)udp + sizeof(*udp) <= data_end)
{
u64 value = htons(udp->dest);
counter.increment(value);
}
}
}
}
return XDP_PASS;
}
Throws error
udp.c:7:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
BPF_HISTOGRAM(counter, u64);
^
udp.c:7:15: error: a parameter list without types is only allowed in a function definition
BPF_HISTOGRAM(counter, u64);
^
udp.c:22:33: error: use of undeclared identifier 'IPPROTO_UDP'
if (ip->protocol == IPPROTO_UDP)
^
udp.c:28:21: error: use of undeclared identifier 'u64'
u64 value = htons(udp->dest);
^
udp.c:29:21: error: use of undeclared identifier 'counter'
counter.increment(value);
^
udp.c:29:39: error: use of undeclared identifier 'value'
counter.increment(value);
^
1 warning and 5 errors generated.
root#fawad:/home/fawad/bpf# gedit udp.c
(gedit:7386): Gtk-WARNING **: 13:24:34.572
https://dev.to/satrobit/absolute-beginner-s-guide-to-bcc-xdp-and-ebpf-47oi
nb: This question has been reduced many times, due to comments.
Below now is presented minimum amount of code which generated the error. inttypes.h file was downloaded from here: ffMPEG "inttypes.h not found" error), which was thought to be the issue in the beginning.
//tlvlist.c
static int32_t test(somestruct *a);
/* Private method, adds tlv object to the list which contains raw binary data. */
int32_t int32_t test(somestruct *a)
{
/* Some checks */
if(a == NULL || bytes == NULL)
return -1;
/* Check if list is full */
if(a->used == MAX_LIST_SIZE)
return -1;
/* Index to first free element in the list */
int iIndex = a->used;
// ...
return 0;
}
errors:
tlvlist.c
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(21): error C2143: syntax error : missing ';' before 'type'
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(23): error C2065: 'iIndex' : undeclared identifier
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(24): error C2065: 'iIndex' : undeclared identifier
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(28): error C2065: 'iIndex' : undeclared identifier
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(29): error C2065: 'iIndex' : undeclared identifier
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(32): error C2065: 'iIndex' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Evidently, when compiling a C file in MSVS you need to have all variable declarations at the start of the function before any statement. For example:
int32_t Tlvlist_AddRawt(Tlvlist *a, uint8_t type, uint16_t size, const void *bytes)
{
/* Index to first free element in the list */
int iIndex;
/* Some checks */
if(a == NULL || bytes == NULL)
return -1;
iIndex = a->used;
...
}
I believe this is old C89 format and most C compilers now use C99 (or greater) which would permit variable declarations anywhere in the function. Renaming the file as CPP is another option for MSVS without moving the variable declarations to the top of a function, though it may raise other issues in the code.
I am trying to define a macro in the format
#define SUM(x,y) ({log_var = x; log_var += y;})
void main(void)
{
unsigned int log_var;
SUM(10,20);
}
Compilation of the same by ARMCC throws an error "Expected an expression" but compilation with GCC doesn't throw the error.
Is it the syntax ({<statements>}); is not allowed in ARMCC or is there any other reason for the same ?
The same disappears when the parentheses is removed. i.e {<statements>}
If you want to have a multi-statement macro body, the usual way is to have a one-iteration do while loop:
#define SUM(x,y) do {log_var = x; log_var += y;} while (0)
I am writing a program in C that uses winsock and I am using the command fcntl to make the receive call nonblocking and I am getting the following errors.
warning C4013: 'fcntl' undefined; assuming extern returning int
error C2065: 'F_SETFL' : undeclared identifier
error C2065: 'F_GETFL' : undeclared identifier
error C2065: 'F_SETFL' : undeclared identifier
error C2065: 'O_NDELAY' : undeclared identifier
error C2065: 'EWOULDBLOCK' : undeclared identifierenter code here
I am including the winsock2.h header file in my code as follows
#pragma comment(lib,"ws2_32.lib")
#include <winsock2.h>
Please help me out.
Thanks in advance.
I think on Windows you need to use ioctlsocket rather than fcntl().
To make non-blocking:
unsigned long on = 1;
if (0 != ioctlsocket(socket_fd, FIONBIO, &on))
{
/* Handle failure. */
}
To make blocking:
unsigned long off = 0;
if (0 != ioctlsocket(socket_fd, FIONBIO, &off))
{
/* Handle failure. */
}
Instead of EWOULDBLOCK use WSAEWOULDBLOCK.
The following code (a function prototype):
void parse_ini(FSFILE *fp, void(*secFunc)(char*), void(*varFunc)(char*, char*));
presents errors when compiled:
util\setup.c:38: error: syntax error before '*' token
util\setup.c:38: error: 'parse_ini' declared as function returning a function
util\setup.c:38: error: syntax error before 'void'
util\setup.c:50: error: syntax error before '*' token
What is causing this? Using MPLAB C30, which is a version of GCC v3.23 for PIC24F/dsPIC 16-bit microcontrollers.
I'd guess that you haven't included a header that declares/defines FSFILE.
try this
typedef void (*varfuncptr)(char *, char*);
typedef void (*secfuncptr)(char *);
void parse_ini(FSFILE *fp, secfuncptr *secFunc, varfuncptr *varFunc);