Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » CDT Code analysis gives errors for custom compilers(CDT Code analysis gives errors for custom compilers)
CDT Code analysis gives errors for custom compilers [message #1008377] Tue, 12 February 2013 08:47
Anitha Y is currently offline Anitha Y
Messages: 14
Registered: February 2010
Junior Member
Hi, we have a custom C/C++ compiler. We have built a new perspective over CDT to support development for C/C++ applications (using the custom compiler). However in some cases, the code analysis is not able to analyse the errors properly. In the below code it throws errors in the editor though the Cygwin build works fine. What could be the issue for this? Is there a way we could teach the code analysis tool to parse the compiler header files correctly (may be inputting some environment variables).

I tried adding the words to Paths and Symbols, but that adds a respective -D option in the compiler and hence compilation fails.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>




static void usage();

int main(int argc, char *argv[]) {
if (argc > 1 && *(argv[1]) == '-') {
usage(); exit(1);
}

int listenPort = 1234;
if (argc > 1)
listenPort = atoi(argv[1]);

// Create a socket
int s0 = socket(AF_INET, SOCK_STREAM, 0);
// Error above saying the below:
// - Symbol 'AF_INET' could not be
// resolved
// - Symbol 'SOCK_STREAM' could not be
// resolved
// - Function 'socket' could not be resolved
// This is inspite of socket.h being in the include path. I was able to open the file by clicking on it. Similar errors in the rest of the file too.

if (s0 < 0) {
perror("Cannot create a socket"); exit(1);
}

// Fill in the address structure containing self address
struct sockaddr_in myaddr;
memset(&myaddr, 0, sizeof(struct sockaddr_in));
myaddr.sin_family = AF_INET;
myaddr.sin_port = htons(listenPort); // Port to listen
myaddr.sin_addr.s_addr = htonl(INADDR_ANY);

// Bind a socket to the address
int res = bind(s0, (struct sockaddr*) &myaddr, sizeof(myaddr));
if (res < 0) {
perror("Cannot bind a socket"); exit(1);
}

// Set the "LINGER" timeout to zero, to close the listen socket
// immediately at program termination.
//struct linger linger_opt = { 1, 0 }; // Linger active, timeout 0
char linger_opt = '1';
setsockopt(s0, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof(linger_opt));

// Now, listen for a connection
res = listen(s0, 1); // "1" is the maximal length of the queue
if (res < 0) {
perror("Cannot listen"); exit(1);
}

// Accept a connection (the "accept" command waits for a connection with
// no timeout limit...)
//struct sockaddr_in peeraddr;
int peeraddr = 1;
int peeraddr_len = sizeof(peeraddr);
int s1 = accept(s0, (struct sockaddr*) &peeraddr, &peeraddr_len);
if (s1 < 0) {
perror("Cannot accept"); exit(1);
}

// A connection is accepted. The new socket "s1" is created
// for data input/output. The peeraddr structure is filled in with
// the address of connected entity, print it.


res = close(s0); // Close the listen socket

write(s1, "Hello!\r\n", 8);

char buffer[1024];
res = read(s1, buffer, 1023);
if (res < 0) {
perror("Read error"); exit(1);
}
buffer[res] = 0;
printf("Received %d bytes:\n%s", res, buffer);

close(s1); // Close the data socket
return 0;
}


Thanks in advance.

[Updated on: Thu, 30 May 2013 10:14]

Report message to a moderator

Previous Topic:Content assist for Eclipse CDT with references not working
Next Topic:CDT API for macro introspections
Goto Forum:
  


Current Time: Tue Sep 23 02:19:29 GMT 2014

Powered by FUDForum. Page generated in 0.02397 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software