C language(asm construct)
hi
i want to know if this is correct? i am a bit confused about linker...i am talking this topic when we have a asm construct in our code.
The compiler basically reads the .c program and converts it into assembly code.Now during this it neglects this assembler construct and leaves it for assembler.Assembler is the person which basically looks for this part of the code and changes it into machine code.
thanks
ankit
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
passing host name from a structure.
Hi Experts,
here a question for you, I have defined the following
#define bcopy(a,b,c) strncpy(b,a,c)
struct sockaddr_in sa; /* socket addr. structure */ struct hostent * hp; /* host entry */
char *hostname;
hostname=argv[3];
hp=gethostbyname(hostname); <-- get this error " warning: assignment makes pointer from integer without a cast
"
bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length); <-- getting dereferencing pointer to incomplete type
Any idea?
thanks in advance
Edward
Re: passing host name from a structure.
Quoted 9 lines · On 06 Oct 2004 16:47:27 -0500 Edward Parrilla <[email protected]> wrote:
Hi Experts,
here a question for you, I have defined the following#define
bcopy(a,b,c)strncpy(b,a,c)struct sockaddr_in sa; /* socket addr. structure */ struct hostent * hp; /* host entry */
Quoted 7 lines
char *hostname;
hostname=argv[3];
hp=gethostbyname(hostname); <-- get this error " warning: assignment makes pointer from integer without a cast
"
so, it's wrong write
hp=gethostbyname((const char*)hostname);/*but why you need pointer hostname? may be use argv[3] instead?*/ see `man gethostbyname' for details
Quoted 18 lines
bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length); <-- getting dereferencing pointer to incomplete typeAny idea?
thanks in advance
Edward-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Alphex Kaanoken, Senior Developer of Crew IT research labs. Web: http://crew.org.ru Mail: kaanoken at crew.org.ru
Re: passing host name from a structure.
I tried with that it didn't work. It works when I add the #include <netdb.h>
however when I add that library, it doesn't allow the "fprintf" and "strupr" to work, any ideas?
Got the following error
/tmp/ccD8SAtf.o(.text+0x37f): In function `main':
: undefined reference to `fprint'
appears as "fprint" even when I put "fprintf"
any ideas?
Quoted 41 lines · Alphex Kaanoken
Quoted 9 lines · On 06 Oct 2004 16:47:27 -0500 Edward Parrilla <[email protected]> wrote:
Hi Experts,
here a question for you, I have defined the following#define
bcopy(a,b,c)strncpy(b,a,c)struct sockaddr_in sa; /* socket addr. structure */ struct hostent * hp; /* host entry */Quoted 7 lines
char *hostname;
hostname=argv[3];
hp=gethostbyname(hostname); <-- get this error " warning: assignment makes pointer from integer without a cast
"so, it's wrong write
hp=gethostbyname((const char*)hostname);/*but why you need pointer hostname? may be use argv[3] instead?*/ see `man gethostbyname' for detailsQuoted 18 lines
bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length); <-- getting dereferencing pointer to incomplete typeAny idea?
thanks in advance
Edward-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: passing host name from a structure.
In reply to Edward ParrillaQuoted 9 lines · Edward Parrilla
#define
bcopy(a,b,c)strncpy(b,a,c)struct sockaddr_in sa; /* socket addr. structure */ struct hostent * hp; /* host entry */char *hostname;
hostname=argv[3];
hp=gethostbyname(hostname); <-- get this error " warning: assignment makes pointer from integer without a cast"
This error looks really peculiar. IIUC, it's complaining that gethostbyname() returns an int (or other ordinal value) which must be converted to a pointer for assignment to "hp". However, on my system "man gethostbyname" says "struct hostent *gethostbyname(const char *name);" which says it should be returning a pointer (even one of the same type as you declared "hp"). Have you declared a prototype for gethostbyname()? If not, then the compiler assumes the function returns an int. The same man page indicates you should include this line in your source: "#include <netdb.h>". Just to be sure, check "man gethostbyname" on your system and see what include files it recommends and what type gethostbyname() returns. If you've confirmed that's not the problem, then you might dig into the include file(s), find the prototype being used for gethostbyname() and see that it's correct; but that's very unlikely to be the problem. (Someone else would have seen it a long time ago.)
Quoted 1 line
bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length); <-- getting dereferencing pointer to incomplete type
The problem is the precedence of "(char *)hp->h_addr". The cast "()" and indirection "->" operators have equal precedence level and so left-to-right order determines precedence, which means you told the compile to access the h_addr struct field of what you just told it is a char. I think you mean "(char *)(hp->h_addr)". Note also that some groups of operators at the same precedence level operate left to right [e.g., arithmetic: (a + b - c)] and others operate right to left [e.g., assignments: (a *= b +=2)].
--
Jeff Woods <[email protected]>
Re: passing host name from a structure.
Thanks,
you were right, it was my mistake I was putting "fprintff" instead of "fprintf"
Quoted 46 lines · Jeff Woods
Quoted 10 lines · Edward Parrilla
#define
bcopy(a,b,c)strncpy(b,a,c)struct sockaddr_in sa; /* socket addr. structure */ struct hostent * hp; /* host entry */char *hostname;
hostname=argv[3];
hp=gethostbyname(hostname); <-- get this error " warning: assignment makes pointer from integer without a cast"
This error looks really peculiar. IIUC, it's complaining that
gethostbyname()returns an int (or other ordinal value) which must be converted to a pointer for assignment to "hp". However, on my system "man gethostbyname" says "struct hostent *gethostbyname(const char *name);" which says it should be returning a pointer (even one of the same type as you declared "hp"). Have you declared a prototype forgethostbyname()? If not, then the compiler assumes the function returns an int. The same man page indicates you should include this line in your source: "#include <netdb.h>". Just to be sure, check "man gethostbyname" on your system and see what include files it recommends and what typegethostbyname()returns. If you've confirmed that's not the problem, then you might dig into the include file(s), find the prototype being used forgethostbyname()and see that it's correct; but that's very unlikely to be the problem. (Someone else would have seen it a long time ago.)Quoted 2 lines
bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length); <-- getting dereferencing pointer to incomplete typeThe problem is the precedence of "(char *)hp->h_addr". The cast "()" and indirection "->" operators have equal precedence level and so left-to-right order determines precedence, which means you told the compile to access the
h_addrstruct field of what you just told it is a char. I think you mean "(char *)(hp->h_addr)". Note also that some groups of operators at the same precedence level operate left to right [e.g., arithmetic: (a + b - c)] and others operate right to left [e.g., assignments: (a *= b +=2)].--
Jeff Woods <[email protected]>-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
mapping client to port
In reply to Jeff WoodsHi all,
sorry again for bothering you:
I have the following entry to do:
myprog port1 port2 servname
that will be executed from the client's command line.
where
port1 is the client's port
port2 is the server's port
and servname is the server to which I want to connect.
In order to associate port2 with servername I have to create a struct servent *serv;
struct socket_in *fin;
then associate it with
fin.sin_port -->getservbyname(port2)
the question is how do to associate the port1 to the local host?
is it valid if I do:
fin.in_port = htons(atoi(port1))
Thanks in advance for your help
Edward
Hi,
Steps:
1) write hello_world.c
2) the preprocesor parse you hello_world.c file, process every # starting commands (like #include #define #ifdef ...) and generate a temporary file
3) the compiler start it's job reading the c file, parsing it, checking it for errors, optimizing it and generating an assembler file
4) the assembler generate than the obj files
5) the linker solve the libraries, global variables referencing, etc and generate the executable which of course, is in machine code and platform dependent.
Retain that step 4 can be optional, the compiler can generate object files without an assembler, it depending on the compilers ;)
So, to move your compiler on another platform, you need a new assembler and linker, the compiler can be the same. Look for example at GNU Compiler family ;)
For more info read
Aho, Sethi, Ullman - Compilers Principles, Techinques, And Tools
Quoted 24 lines · Ankit Jain
hi
i want to know if this is correct? i am a bit confused about linker...i am talking this topic when we have a asm construct in our code.
The compiler basically reads the .c program and converts it into assembly code.Now during this it neglects this assembler construct and leaves it for assembler.Assembler is the person which basically looks for this part of the code and changes it into machine code.
thanks
ankit
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html