• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Need some help with a linked list in C. I have a client-server program with communication over tcp and udp. When clients connect to the server they are added to a linked list and a communication thread is created for that connection.

Problem is that the thread that adds the client to the list loops endlessly when i try to connect a second client. It doesn't do that when i remove the add_llist() function, so I'm sure there's something wrong with that function. It's probably the most obvious thing ever, but I just cant figure out what causes it.

This is my code: http://pastebin.com/tCxey1DA

Try explicitly initialising the "next" pointer to 0 in your init_node function and see if it makes a difference. I expect it will, but haven't touched C for a while.
 

Ziltoid

Unconfirmed Member
Try explicitly initialising the "next" pointer to 0 in your init_node function and see if it makes a difference. I expect it will, but haven't touched C for a while.
Still the same unfortunately.

Also: If I set the head->next pointer to 0 instead of tail in init_llist() I can add three clients until the same problem occurs for some reason.
 
Still the same unfortunately.

Also: If I set the head->next pointer to 0 instead of tail in init_llist() I can add three clients until the same problem occurs for some reason.

That would be because the "else if" statement is only triggered if you set head->next to 0 instead of tail (otherwise there's already a second item in the list).

Second thing I'd check is if the allocation is actually succesful in your init_node function. Check to see if the node that is returned is actually a null pointer.
 

Ziltoid

Unconfirmed Member
Doh! it was the if statement in the while loop in add_llist(). It should have checked if it->next == tail, not 0.

Thanks anyway, dutchguyjack.
 

sans_pants

avec_pénis
hey so i've learned a good bit of html and css, along with the beginnings of java. can you guys recommend any books that take like a general look at computer logic? my fundamentals arent very strong and i never took any sort of cs classes in college


id prefer something less dry than a textbook, but ill take whatever
 
hey so i've learned a good bit of html and css, along with the beginnings of java. can you guys recommend any books that take like a general look at computer logic? my fundamentals arent very strong and i never took any sort of cs classes in college


id prefer something less dry than a textbook, but ill take whatever

http://www.amazon.com/dp/1848900252/?tag=neogaf0e-20

It's the book I learned Java from at University. It's written by my then-lecturer, a really fun guy to listen to, and uses a very ligthearted, humorous but very logical way of writing.

It's one of the best Java books I've read, and I'd easily recommend it to anyone who's looking to get into Computer Programming. Takes you all the way from the basics to the very advanced stuff.
 

squidyj

Member
Alright, so in our final assignment we're working with threads and system calls and signals and whatnot. I've finished everything except for one part of the assignment we need to create as many threads as we can in 3 seconds, 10 times over. We do this twice, once using pthread_create and once using clone or vfork.

My pthread implementation works fine but my clone implementation segfaults on occasion. This is what the relevant code looks like.

Code:
#define STACK_SIZE 4096
#define TEST_COUNT 10
...

int clone_child(void *param)
{
	return 1;
}

void test_clone(int list[])
{
	int i, temp, flags;
	char *end, *stack;
	flags = (CLONE_VM | CLONE_THREAD | CLONE_SIGAND);
	end = malloc(STACK_SIZE);
	if(end == NULL)
		return;
	stack = end + STACK_SIZE;
	for(i = 0; i < TEST_COUNT; i++)
	{
		cont = 1;
		//SIGALRM sets cont to 0
		alarm(3);
		while(cont);
		{	
			//arguments in order, function, stack address, flags, function arguments
			temp = clone(clone_child, stack, flags, NULL)
			if(temp > 0)
			{
				list[i] += 1;
			}
		}
		printf("Iteration %d spawned %d threads \n", (i + 1), list[i]);
	}
}

...
 

tokkun

Member
Alright, so in our final assignment we're working with threads and system calls and signals and whatnot. I've finished everything except for one part of the assignment we need to create as many threads as we can in 3 seconds, 10 times over. We do this twice, once using pthread_create and once using clone or vfork.

My pthread implementation works fine but my clone implementation segfaults on occasion. This is what the relevant code looks like.

Hmm...are you sure it's safe to have all your child threads share the same stack?
 

sans_pants

avec_pénis
http://www.amazon.com/dp/1848900252/?tag=neogaf0e-20

It's the book I learned Java from at University. It's written by my then-lecturer, a really fun guy to listen to, and uses a very ligthearted, humorous but very logical way of writing.

It's one of the best Java books I've read, and I'd easily recommend it to anyone who's looking to get into Computer Programming. Takes you all the way from the basics to the very advanced stuff.

thanks ill check it out
 

Milchjon

Member
Is there a way to find out more about errors in Visual Studio 2012?

Because right now I can't seem to create Win 32 console programs/projects. I can create websites and single C++ files, and open old projects.

It only gives me a "Error creating the project" (Or something similar, it's German) when I try to create a new one, and apparently that isn't specific enough to efficiently hunt for solutions on Google. Or at least I haven't found much relevant stuff so far.

Is there any way to get more info within Visual Studio? Or will I have to just try and reinstall it?
 
Is there a way to find out more about errors in Visual Studio 2012?

Because right now I can't seem to create Win 32 console programs/projects. I can create websites and single C++ files, and open old projects.

It only gives me a "Error creating the project" (Or something similar, it's German) when I try to create a new one, and apparently that isn't specific enough to efficiently hunt for solutions on Google. Or at least I haven't found much relevant stuff so far.

Is there any way to get more info within Visual Studio? Or will I have to just try and reinstall it?

We need more information on the error.
 

Milchjon

Member
We need more information on the error.

That's what I was trying to ask here, how to find more info on it :-D


Basically, I'm trying to create a new Win32 console project, it does nothing and gives me this message:

GQxR6ch.png


Like I said, that's the only thing it says down in the left corner, and since that obviously isn't enough information, I can't find much on it. No error code or anything else.

So is there some place within Visual Studio which expands upon the info in the message?

Or will I have to search forever on Google.
 
That's what I was trying to ask here, how to find more info on it :-D


Basically, I'm trying to create a new Win32 console project, it does nothing and gives me this message:

GQxR6ch.png


Like I said, that's the only thing it says down in the left corner, and since that obviously isn't enough information, I can't find much on it. No error code or anything else.

So is there some place within Visual Studio which expands upon the info in the message?

Or will I have to search forever on Google.

Might want to reinstall Visual Studio.
 

usea

Member
That's what I was trying to ask here, how to find more info on it :-D


Basically, I'm trying to create a new Win32 console project, it does nothing and gives me this message:

GQxR6ch.png


Like I said, that's the only thing it says down in the left corner, and since that obviously isn't enough information, I can't find much on it. No error code or anything else.

So is there some place within Visual Studio which expands upon the info in the message?

Or will I have to search forever on Google.
Well I don't understand German, but maybe the location or name you've picked for the project is invalid or something?
 

Milchjon

Member
It says building error? Does C++ have a "Clean Solution" option under build for you? Try that.

I'm pretty clueless, so bear with me, but you're talking about compiling, right?

This error comes up when I first try to create a new project, before any coding has taken place.
 

Harpuia

Member
Have absolutely no idea why my compiler is recognizing this function as if it has all it's parameters as call-by-reference. Any tips?

Code:
while(! details.eof())
    {
		details >> iD;
		details >> name >> dOB >> socialSecurity >> department >> position;
		Employees.fillArray(finalCount, iD, name, dOB, socialSecurity, department, position);
        finalCount++;
    }

Also here's filArray func:

Code:
void Employeemgmt::fillArray(int index, int iD, string name, string dOB, string socialSecurity, string department, string position)
{
    this->EmployeeArray[index].setID(iD);
    this->EmployeeArray[index].setName(name);
    this->EmployeeArray[index].setdOB(dOB);
    this->EmployeeArray[index].setSS(socialSecurity);
    this->EmployeeArray[index].setDepartment(department);
    this->EmployeeArray[index].setPosition(position);
}

And the member function that the function is calling which is part of class Employee:

Code:
void Employee::setID(int number)
{
    this->iD = number;
}

void Employee::setName(string name)
{
    this->name = name;
}

void Employee::setdOB(string dOB)
{
    this->dOB = dOB;
}

void Employee::setSS(string socialSecurity)
{
    this->socialSecurity = socialSecurity;
}

void Employee::setDepartment(string department)
{
    this->department = department;
}

void Employee::setPosition(string position)
{
    this->position = position;
}
 

Slavik81

Member
C++ is cool and all but....

Fuck Access Violation errors.

Alas, a crash to desktop on an out-of-bounds access is better than most other alternatives you'd face in C++. Silent corruption is far, far worse.

Run your program through a debugger and take a look at the stack when it crashes.

Have absolutely no idea why my compiler is recognizing this function as if it has all it's parameters as call-by-reference. Any tips?
Post the error message.

I'm at a crossroads. What language do you guys use for Windows-based tools development?

I'm creating a level editor. My game is written in C++. I would like the editor to use the same graphics engine that my game runs - DirectX. I already built an easy-to-use engine around DirectX, so why not use it here?

So I'm trying to decide what language to code the tool in. I've contemplated C++ with the Win32 API, MFC, .NET...

.NET is kinda tricky since I'd need a wrapper for DirectX, and couldn't use my graphics library without another wrapper... or I can say screw DirectX and create some graphics routines through .NET...

What do you guys code simple level editors in?
I would build my level editor on the same code base used for the game itself. You'll work faster with a coding style you're already familiar with and you should be able to share a decent chunk of code between the tool and the game.
 

jokkir

Member
I just wanted to thank nekura for helping me figure out the problem of my program crashing! I can't tell you how long I spent trying to figure out what the problem was... and it wasn't where I thought the problem was ><

Thank you again :)
 

nan0

Member
That's what I was trying to ask here, how to find more info on it :-D


Basically, I'm trying to create a new Win32 console project, it does nothing and gives me this message:

GQxR6ch.png


Like I said, that's the only thing it says down in the left corner, and since that obviously isn't enough information, I can't find much on it. No error code or anything else.

So is there some place within Visual Studio which expands upon the info in the message?

Or will I have to search forever on Google.


Have tried to start VS as Administrator? You can also try to create a log file: http://msdn.microsoft.com/en-us/library/ms241272(v=vs.110).aspx. Are there maybe Umlaute in the path where you want to create the project (your name)? Normally shouldn't be an issue, though.
 

Magni

Member
Eclipse is a steaming pile of shit. That is all. I'm currently taking a course on Java EE development, and it's an exercise in frustration (I did a co-op in a startup working on Ruby-on-Rails last semester, everything was so much smoother).
 
Eclipse is a steaming pile of shit. That is all. I'm currently taking a course on Java EE development, and it's an exercise in frustration (I did a co-op in a startup working on Ruby-on-Rails last semester, everything was so much smoother).

It's a great IDE I think. I haven't done any Java EE development on it so I'm not sure what your frustrations are though.
 
It's a great IDE I think. I haven't done any Java EE development on it so I'm not sure what your frustrations are though.

The only issue I've ever had with it is a decent vi plugin. Almost everything I've played with runs into some sort of problem / bug. I've never had any issues with Visual Studio's vi plugins.
 
Eclipse is a steaming pile of shit. That is all. I'm currently taking a course on Java EE development, and it's an exercise in frustration (I did a co-op in a startup working on Ruby-on-Rails last semester, everything was so much smoother).

I think it's a pretty good IDE. What is giving you trouble?
 
I would build my level editor on the same code base used for the game itself. You'll work faster with a coding style you're already familiar with and you should be able to share a decent chunk of code between the tool and the game.

Thanks for the advice. Still at the cross-roads :( I've progressed in both directions a bit... but need to choose a path.

C++ or C#... hmmm....
 
Eclipse is a steaming pile of shit. That is all. I'm currently taking a course on Java EE development, and it's an exercise in frustration (I did a co-op in a startup working on Ruby-on-Rails last semester, everything was so much smoother).

I agree. When I first got my internship in .NET I realized just how far superior Visual Studio is to Eclipse. Everything is just so much better.

BTW, guys what do companies actually expect from an intern? I mean I'm doing real software development and actually developing products that would be shipped out the door. However, although I can usually code them my programs are riddled with bugs. I always get the general logic but constantly screw up with either an off by 1 error, a null exception or simply forget a functionality that I only realize I forgot after implementing something else that would require it. Furthermore, often when I do write something that works I realize I did it in a shitty way and it could have been done better and go re-factor it so it is done properly. Is this normal or am I just REALLY bad at my job. Is it fine to constantly go back and fix code you already wrote?
 

Magni

Member
^ I worked in a small startup like I mentioned above, so all my code was pushed out to production. I broke a page once (in staging and an admin-only page) early on in the internship, made sure not to do that again haha. Be careful and test your code. Don't push your code if you're not sure that everything is working as expected.

It's a great IDE I think. I haven't done any Java EE development on it so I'm not sure what your frustrations are though.

The only issue I've ever had with it is a decent vi plugin. Almost everything I've played with runs into some sort of problem / bug. I've never had any issues with Visual Studio's vi plugins.

I think it's a pretty good IDE. What is giving you trouble?

I'd updated a file and it would load the old page in the browser, despite restarting the server multiple times, and deleting and creating a new server. I had to quit out of Eclipse and restart it. And that's just the last issue. I'm not the only one it's happened to, the guy sitting next to me actually had to restart the computer for it to register the saved changes.

That and the editor itself sucks balls compared to Sublime Text 2. The only thing I like about it is auto-creating getters and setters and toString etc, but then again you don't even need to do that with Ruby.

I guess I just miss only needing a text editor and a terminal to do everything (yes I know I could technically do my Java projects with only a text editor and a terminal but it'd be a giant pain in the ass).
 

Fjolle

Member
Eclipse is a steaming pile of shit. That is all. I'm currently taking a course on Java EE development, and it's an exercise in frustration (I did a co-op in a startup working on Ruby-on-Rails last semester, everything was so much smoother).

Everybody i know that has used it has told me the same.. Have you tried Intellij?
 

Magni

Member
Everybody i know that has used it has told me the same.. Have you tried Intellij?

Not yet no. I have four projects right now, with Java EE, Scala, Groovy/Grails, and an Android app, and for the first two the professors asked us to use Eclipse (I have to use Eclipse for the Java EE one actually since it's on a school computer and we can't install anything...) so I'm using it for the other two as well.

At the end of this semester I'm uninstalling it though, and next time I need to do any Java dev I'll look at IntelliJ - it can't be worse can it? :lol
 

Yamauchi

Banned
I used to hate Eclipse too, but it has grown on me, especially for Java development. I now use it almost exclusively after having used MSVS, Code::Blocks, and NetBeans in the past. For scripting, I prefer Kate.
 

upandaway

Member
So I've seen some Python code by, uh, coincidence, and I'm getting a strong urge to stop whatever I'm doing with Java and just start learning that. But hell, I'll give it some more time out of fear of knowledge deleting itself to make room.

Also I gave up on unit testing for whatever 1-day stuff I've been doing lately. I think I get it, maybe, hopefully, but there's just no point when it's a small thing. Also keeping classes orthogonal is really hard!
 

nan0

Member
IntelliJ IDEA is really good, I recently switched (for Android development) because I too think that eclipse is just bad. If you seriously have to consider to rather reinstall the newest version than risking to install core updates, there is something wrong with a software. And it doesn't have a fully dark UI skin. Even VS has one now.

BTW, guys what do companies actually expect from an intern? I mean I'm doing real software development and actually developing products that would be shipped out the door. However, although I can usually code them my programs are riddled with bugs. I always get the general logic but constantly screw up with either an off by 1 error, a null exception or simply forget a functionality that I only realize I forgot after implementing something else that would require it. Furthermore, often when I do write something that works I realize I did it in a shitty way and it could have been done better and go re-factor it so it is done properly. Is this normal or am I just REALLY bad at my job. Is it fine to constantly go back and fix code you already wrote?

You're doing it wrong if you don't do this, but prioritize it. If you notice lots of errors, try being a bit more structured. Do some rough diagrams on paper, make a list of requirements and think about an outline before you actually start to code.
Refactoring is fine if it's an easy and clear fix (extracting a method for example) or a blatant error, but don't expect and try to write 100% perfect code. And don't refactor someone elses code unless it's your job or you can discuss it with the original author.
 

Harpuia

Member
Post the error message.


||=== project2, Debug ===|
In function `int main()':|
28|error: no matching function for call to `Employeemgmt::fillArray(int&, int&, std::string&, std::string&, std::string&, std::string&, std::string&)'|
8|note: candidates are: void Employeemgmt::fillArray(int, std::string, std::string, std::string, std::string, std::string)|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|

As you can see, the function does exist but for some reason it thinks I'm calling a function with the same parameters, but the parameters are called by reference for some reason.

uhhhh durr I just figured it out. forgot to initialize a parameter in my class definition. God I hate it when it's something as simple as that. :/
 
IntelliJ IDEA is really good, I recently switched (for Android development) because I too think that eclipse is just bad. If you seriously have to consider to rather reinstall the newest version than risking to install core updates, there is something wrong with a software. And it doesn't have a fully dark UI skin. Even VS has one now.



You're doing it wrong if you don't do this, but prioritize it. If you notice lots of errors, try being a bit more structured. Do some rough diagrams on paper, make a list of requirements and think about an outline before you actually start to code.
Refactoring is fine if it's an easy and clear fix (extracting a method for example) or a blatant error, but don't expect and try to write 100% perfect code. And don't refactor someone elses code unless it's your job or you can discuss it with the original author.

This is good advice. A quote I often use is it's better to think twice and program once than to think once and program twice.

Edit - There's occasions where you have to program something in a way you don't want it to be, but have to for the time being for whatever reason. In those cases, make sure you comment your code with a TODO to remind yourself later.
 

usea

Member
||=== project2, Debug ===|
In function `int main()':|
28|error: no matching function for call to `Employeemgmt::fillArray(int&, int&, std::string&, std::string&, std::string&, std::string&, std::string&)'|
8|note: candidates are: void Employeemgmt::fillArray(int, std::string, std::string, std::string, std::string, std::string)|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|

As you can see, the function does exist but for some reason it thinks I'm calling a function with the same parameters, but the parameters are called by reference for some reason.
I find that if I phrase the question a different way, it usually helps me get to the solution more quickly. Don't phrase it like the compiler isn't understanding your code correctly, phrase it like you're not correctly informing the compiler with your code.

In other words, it's not "the compiler thinks I'm calling by reference for some reason."

Instead it's "Why am I calling it with a bunch of reference parameters?"

Accept what the compiler tells you as fact, and try to work out why those facts conflict with your intention.

(I don't have enough C++ knowledge on hand to help you actually solve your problem. But I'd guess that it's either something not in the code you pasted, or that the >> operator is doing it. If you dereference (*) the parameters you pass in, does it fix the problem?)
 

luoapp

Member
||=== project2, Debug ===|
In function `int main()':|
28|error: no matching function for call to `Employeemgmt::fillArray(int&, int&, std::string&, std::string&, std::string&, std::string&, std::string&)'|
8|note: candidates are: void Employeemgmt::fillArray(int, std::string, std::string, std::string, std::string, std::string)|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|

As you can see, the function does exist but for some reason it thinks I'm calling a function with the same parameters, but the parameters are called by reference for some reason.

uhhhh durr I just figured it out. forgot to initialize a parameter in my class definition. God I hate it when it's something as simple as that. :/

What's line 28 of main()? The number of args is not the same (7 vs 6), unless that's a typo.
 
Top Bottom