• 0

C++ source code


Question

As i'm not really asking for help rather just a general discussion that has bothered me for some time involving c++ (i felt this would be the right place but if not feel free to move it to programming section)

I've been put off c++ for a long time and even now as i want to use it more there are little things that always seem to bite me in the rear

has anyone else ever had issues with downloading someone else's source code to play with to find that it never works correctly? i always think i'm doing something wrong but this is starting to get ridiculous

I wanted to write a little server program using sockets under Linux (ubuntu) and i thought to myself i'll look around the net for a socket solution so i don't waste to much time on it...anyway i came across this site

http://coderstalk.blogspot.com/2008/02/sim...ramming-in.html

a tgz file was available for download including the source and pretty much everything i needed so i decided to download it through linux using wget

i then unzipped the files using the information provided by the site and once the files were extracted i typed "make" to compile the files so i could use them

straight away i get hit back with errors preventing the code from working (i've downloaded several samples so far with this same problem so this was kind of the last straw)

Am i the only one experiencing this issue? am i missing some highly general/common knowledge that i'm meant to apply before i can download and try other peoples source code? why is it such an issue in c++ to have code that simply works correctly without me having to add extra stuff that is never mentioned

so i ask am i the only one?

(fyi the issue was

second argument of 'int main(int, int*)' should be 'char **'
)
Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

while i'm on the subject does anyone have a link to a simple working implementation of sockets under ubuntu 9.04 ? preferable with tcp and it doesn't matter if its blocking or not i plan to figure the rest out i just need a working entry point (first time developing for linux)

also i'm using the server edition of ubuntu if that helps

Link to comment
Share on other sites

  • 0

in the 2 simple_X_main.cpp fails, change:

int main ( int argc, int argv[] )

to

int main ( int argc, char* argv[] )

I've never seen the 2nd argument to main() be an int[], googling comes up with nothing except 1 thread tell someone to change it to char* which afaik is the only type allowed.

Link to comment
Share on other sites

  • 0

Ah thanks a lot there was a few more issues after it but i fixed (iostream wasn't included) i just find it frustrating that broken code makes it on these help sites its not very encouraging for people trying to learn it first time

Link to comment
Share on other sites

  • 0
Ah thanks a lot there was a few more issues after it but i fixed (iostream wasn't included) i just find it frustrating that broken code makes it on these help sites its not very encouraging for people trying to learn it first time

One problem I've come across is programmers who want to say they support open source and release code but at the same time purposely sabotage and/or alter their code to make it more difficult for someone to understand and modify it. These are the sort of people who will say in a chat 'Sure I made the source available, but I don't make it easy for them :p'

It's this kind of smugness that really gets on my nerves. It's as if they want to be the only one with their code implementation but want to make it available anyway just so whoever gets it has to come grovelling to them to explain it all so they can feel big about whatever it is they made.

Obviously I don't think this sort of thing is common but it exists and may be a part (even a small part) of why some code you get has these little niggles.

Link to comment
Share on other sites

  • 0
One problem I've come across is programmers who want to say they support open source and release code but at the same time purposely sabotage and/or alter their code to make it more difficult for someone to understand and modify it. These are the sort of people who will say in a chat 'Sure I made the source available, but I don't make it easy for them :p'

It's this kind of smugness that really gets on my nerves. It's as if they want to be the only one with their code implementation but want to make it available anyway just so whoever gets it has to come grovelling to them to explain it all so they can feel big about whatever it is they made.

Obviously I don't think this sort of thing is common but it exists and may be a part (even a small part) of why some code you get has these little niggles.

yeah its quite frustrating and infact put me off c++ when i was younger purely because there was somethings i wanted to build but needed to see some working examples (I love ripping apart a program and seeing exactly how it works) but if the program doesn't work then its useless for my learning ^_^ so i stayed with vb where everything was significantly easier to debug

ah well once i've gotten my working sample code and breaking it up to see what i actually need to get this thing going :D

Link to comment
Share on other sites

  • 0

Don't bother with crappy code. If you need a decent socket tutorial : http://beej.us/guide/bgnet/ .

Am i the only one experiencing this issue? am i missing some highly general/common knowledge that i'm meant to apply before i can download and try other peoples source code? why is it such an issue in c++ to have code that simply works correctly without me having to add extra stuff that is never mentioned

so i ask am i the only one?

You're not. C++ is one of most difficult programming languages to use correctly, and as a result, very few people do use it correctly. If you don't need the performance I suggest you use Python instead. You'll get your program done at least 3 times quicker, that's guaranteed; and to boot, it'll be cross-platform, won't need to be compiled and will be easy to maintain.
Link to comment
Share on other sites

  • 0
Don't bother with crappy code. If you need a decent socket tutorial : http://beej.us/guide/bgnet/ .

Thanks i'll check it out (i ended up discarding that code and working with my php version they seem rather similar in most aspects)

You're not. C++ is one of most difficult programming languages to use correctly, and as a result, very few people do use it correctly. If you don't need the performance I suggest you use Python instead. You'll get your program done at least 3 times quicker, that's guaranteed; and to boot, it'll be cross-platform, won't need to be compiled and will be easy to maintain.

I love c++ don't get me wrong (mainly visual studio since i can use inline asm till my hearts content) however when i want to learn something new all the examples just never work for me so i have to stick to writing standard code and not being able to venture into more complicated things (and resort to using vb for most of it)

i like the challenge of learning something new but yeah if the teachers can't do it right themself then i shouldn't be learning from them :p but yeah thanks again i'll check that link out now

Link to comment
Share on other sites

  • 0
Am i the only one experiencing this issue? am i missing some highly general/common knowledge that i'm meant to apply before i can download and try other peoples source code? why is it such an issue in c++ to have code that simply works correctly without me having to add extra stuff that is never mentioned

so i ask am i the only one?

No, you're far from being the only one. The problem is that there are many versions of the C++ and many C++ compilers which supports different partial sets of the C++ features.

It's very difficult to make portable C++ across platforms and across versions of the C++ compilers and a lot of people cannot or will not support other platforms.

I tried recently Visual Studio 2010: code that compiled nicely with VS 2008 raise compilations errors because Microsoft corrected (rightfully so) some incorrect constructions after revisions of the C++ standards.

It's not just code available on some blogs, even well known packages do not compile out of the box on some platforms variations. Some code can compile in Win32 x86 32-bits mode but fails miserably in x64 64-bits mode.

My advice: check what are the supported platforms (or the platform the developer uses), the closer you are, the more you can expect that it will compile out of the box. If it does not compile, a small detour on your favorite search engine, a little peak in the documentation and a lot of elbow grease do the trick.

Link to comment
Share on other sites

  • 0

Also, not only compilers vary across the different platforms, also the header files do.

I've had a hard time porting a program I had to hand in at my university to Linux, as I originally developed it on OSX, and some headers on the Linux boxes they test the code were broken/outdated.

Link to comment
Share on other sites

  • 0
No, you're far from being the only one. The problem is that there are many versions of the C++ and many C++ compilers which supports different partial sets of the C++ features.

It's very difficult to make portable C++ across platforms and across versions of the C++ compilers and a lot of people cannot or will not support other platforms.

I tried recently Visual Studio 2010: code that compiled nicely with VS 2008 raise compilations errors because Microsoft corrected (rightfully so) some incorrect constructions after revisions of the C++ standards.

It's not just code available on some blogs, even well known packages do not compile out of the box on some platforms variations. Some code can compile in Win32 x86 32-bits mode but fails miserably in x64 64-bits mode.

My advice: check what are the supported platforms (or the platform the developer uses), the closer you are, the more you can expect that it will compile out of the box. If it does not compile, a small detour on your favorite search engine, a little peak in the documentation and a lot of elbow grease do the trick.

I completely agree and i would always assume that to be the case but when i grabbed this code stating it used g++ on linux i just felt there couldn't be anything else that i'm missing and this should just work and since it didn't i had to come vent here :p

main thing throwing me off is how similar php sockets is to c++ sockets however they are still worlds apart in certain aspects, however the beej's site seems highly informed i did read some but had to stop for work will continue with it now thanks again everyone i don't feel as dumb anymore for things not working :p

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.