@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet
Page: 1 2



Comments:

<0> hey, im a real beginner to C, i've done lots and lots of coding on different languages, especially .NET on which i wrote an IRC server from scratch, but im struggling to get started with C now... i have a question which might confuse some of you quite a bit, it's weird but i don't know how to fix this
<0> I got a project on DevC++ (using C, though, not C++), and i got 2 files, obviosly main.c for the main() function, and sockets.c, an attempt to use sockets and connect to my ircd (after all i need a project to work on to get started :)).
<0> The problem is, i can't seem to call any functions in sockets.c from main.c, and i don't know why. I prototyped them in sockets.h, which i include in main.c and sockets.c, but it doesnt make a difference. i tried googling it, but it's hard to think of the right keywords, i didnt find any help there...
<0> 'twould be nice if anyone would be awake and able to help me ;)
<0> though, i feel a bit ashamed of asking such a noob question
<0> its weird, when compiling it says
<0> int closeSock(int s);
<0> bool connectSock(int s, char *addr, int port);
<1> there is a program called the linker.
<0> int closeSock(int s);
<0> bool connectSock(int s, char *addr, int port);
<0> ahh, wrong copy
<0> thats what im prototying, it says theres a syntax error before "connectSock", and when i dbl click the msg it points me to these lines
<1> linking is simething that is not done with interpreted languages.
<1> something even.
<0> yeah i know what the linker does, but i think these errors happen during compilation



<1> so what is the error message?
<0> int closeSock(int s);
<0> bool connectSock(int s, char *addr, int port);
<0> damnit
<0> sockets.c:7: error: syntax error before "connectSock"
<0> sockets.c:7: warning: data definition has no type or storage cl***
<0> there we go
<1> C has no type called bool.
<0> it doesnt?
<1> nope.
<1> well.. C99 has.
<1> if you include stdbool.h
<0> hmmm
<0> its something im just used to, in C
<0> in C# and C++ i think there is bool
<1> yes, they have it.
<0> i just ***umed there would be bool in C, the editor even formated it in bold
<1> but C is not C# or C++.
<0> of course ;)
<0> oh well
<1> you can define your own "bool" of course.
<0> guess thats where i have to pick up then, oh well, silly me, i hope you don't have people like me often
<0> im open to suggestions
<1> typedef int bool
<1> with a semicolon.
<1> and then #define TRUE 1
<1> #define FALSE 0
<0> yeah, i already defines those
<0> ture and false i mean, okay, now i get it to compile
<0> it won't link yet, though
<0> sockets.o(.text+0x1b):sockets.c: undefined reference to `WSAStartup@8'
<0> hmm, missing libraries?
<1> yep.
<1> msdn will tell you which library has WSAStartup()
<0> well, im using dev c++, i think it's using mingw and i have lots and lots of lib's in the lib folder where its suppossed to look, i believe it should be w_sock32 or something like that and its there, do i need to put it in there somewhere explicitely? or is this something i can lookup on the web?
<1> I don't know. IDEs are bad for brains.
<0> hehe
<0> depends if youre used to unix, i'd agree in that case, but im used to coding Console Applications under windows, mainly in .net, IDE's are just kinda natural to me
<0> oh well, i'll try to find something on the web
<1> linker usually has to be told about any libs you need.
<0> gcc.exe main.o sockets.o -o "IRCClient.exe" -L"C:/Dev-Cpp/lib"
<0> i thought this is how it tells the linker to look in that directory
<1> look yes, but it does not know what library it needs.
<1> it wont just pick one that has a correct symbol since many libraries may have the same ones.
<0> they're not defined in the .h files (winsock2.h in this case) ?
<1> no.
<1> header files contain function prototypes, defines, enums, structs whatnot, but that is a totally separate issue from linking.
<1> okay, well, not totally.
<1> programmer needs to know what library needs which headers, or vice versa.
<0> okay
<0> well, this is all kinda new to me
<0> if i can get it to link then youre my hero for tonight ;)
<0> when i got that sorted out i think i can launch from there myself, its not that i can't talk to computers, but starting out is always hard at first
<1> so it needs to be something like: gcc.exe main.o sockets.o -o "IRCClient.exe" -L"C:/Dev-Cpp/lib" wsock32.lib
<1> you may need to put the libs and object files in order so that the files that provide used functions come before the users.
<0> for soem reason it says it won't find the file, it's named "libwsock32.a" in the libs folder here
<0> ahhh
<0> got it
<0> there we go
<0> man you really helped me out here, i think i learned quite alot now, this should get me going
<0> thank you



<1> no problem.
<2> o7
<3> hello
<4> moin
<5> hi
<5> I have small question. I have shared library, where is global var int count; and than I have in client global var int count; Why I don't have to declare it as extern?
<6> because else you would have 2 variables with the same name
<7> i don't think this will work
<7> if both are non-extern
<5> but it warks ..
<5> works
<8> Douglish: actually, you _have_ to declare it as extern
<7> you'll get "multiple definition of `x'" if you link the stuff together
<5> so I'm confused
<8> but gcc and other compilers have some thingys which allow ommitting extern
<5> I see, so it does automaticaly?
<5> somehow ?
<6> why not use extern
<6> you get funny errors and then you'll be asking here what those errors are
<8> Douglish: no, your code is wrong, and gcc uses a "hm maybe he meant xxx..." feature which _may_ do what you wanted
<5> I use it, but I forgot it to declare and it works, so I don't understand why :)
<4> you *declare* it as "extern int count". you *define* it as "int count"
<7> if you declare them extern in _both_ modules, you'll get "undefined reference to `x'" as soon as you try to use it
<8> but after all, your code is still wrong, and gcc may do it wrong, too
<7> can you show your actual code?
<7> (remove unnecessary parts if necessary)
<7> maybe you overlook something
<5> in each code it is as int count; and than is called function from library, which changes value in it and in client it's changes even it's declared as extern in client .. so I was confused
<9> Douglish: also keep in mind, that two external variables, that are meant to be different, *MAY* become the same variable (if the type matches), if the compiler/linker likes to.
<5> I see
<9> you may have file_1.c int count; and in file_2.c: int count;
<9> the compiler may or may not consider this variable as the same one
<5> I see
<7> ping-pong: then you get "multiple definition" as i said above
<9> zap-zero: yes, if both are visible at the same time, in the compiler. However, at linking time, you *may* get both of them
<8> http://pbot.rmdir.de/5041cc356237e6b321888611dcbc0fad
<7> ping-pong: hm, ok
<8> zap-zero: you get this error only if the compiler and linker supports it
<8> the gcc linker e.g. is really ****ty concerning this
<5> hm ..
<6> the proper way to do this is 1) not have extern variables at all, and 2) if you must, declare them in a proper header that goes with your lib
<10> the c standard requires a strict ref/def model where a single definition is allowed, but some linkers use common model where multiple definitions are allowed.
<8> Douglish: in the end it boils down to this: declare global objects (using extern) as often as you want, implement them (omitting the extern) only once, or else you'll get undefined behaviour depending on compiler implementation and other things
<9> knilchBot: add to this: Have the "interface" to that variable, in a common .h file, and make sure you #include that.h everywhere you need to access that variable
<5> http://pastebin.com/852612
<8> "gcc links it without warning" doesn't mean that the result will do what you wanted, and it also doesn't mean that other compilers or other gcc versions will even link that
<5> Ok
<5> I wanted to know, thank you very much .. :)
<11> the table of 150 pointers is *tab[150] right?
<6> yes
<11> thx ;)
<1> Douglish, you better not name your library libm since that is the name of the standard math library.
<5> Auris: yes I know, this was only for demonstration purpose :)
<12> is there some way to set breakpoint on syscall entry in gdb?
<6> you *might* want to set breakpoint on syscall() or __syscall()
<6> but no idea as usual
<12> that'd depend on glibc :/
<12> i'd really want to break on the actual syscall
<6> what are you doing
<12> this time i want to see the arguments to an ioctl and i'm too lazy to recompile to get line number info
<12> strace only shows the pointer
<12> 11875 ioctl(3, VIDIOCSWIN, 0x8053030) = -1 EINVAL (Invalid argument)
<12> gdb sources mention PTRACE_SYSCALL only in one comment
<12> maybe i need to write gdb clone in subterfugue <3
<12> python would allow very high level of interactivism
<6> I need food
<12> three lines of python did it
<13> which three lines feed you?!
<6> :)
<12> domen: heh :)
<4> i hate computers *sigh*
<13> they're kind of like family... you can hate them, but you can't get rid of them, and have to deal with them all the time
<4> hehe
<4> well, i'm having a weird apache problem which no-one on any irc channel i know of, nor anyone on users@ seems to have a clue abot


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #c
or
Go to some related logs:

php undeclare functions
#worldchat
#html
#worldchat
#london
tutti i nik lamer
#worldchat
#worldchat
#worldchat
#worldchat



Home  |  disclaimer  |  contact  |  submit quotes