• 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

squidyj

Member
I have to be doing something horribly horribly wrong or else I'm going to be an incredibly famous (in Computer Science) millionaire.


wtf?
 

squidyj

Member
Hmm, I was trying to avoid having crazy amounts of code up. This is my best attempt to shorten it into what's happening:

Linked list function that adds nodes to the tail (**info is actually that last node's next pointer)
Code:
void listValues( char *integer, struct values **info )
{
     struct values* current = (struct values*)malloc(sizeof(struct values));

     current->num = atoi(integer);
     current->next = *info;
     *info = current;
}

In another function, a switch case performs the operation (addition in this case), stores it in the next to last node and cuts ties with the last node.
Code:
case '+':
     first = first + second;
     replacement->num = first;
     replacement->next = '\0';
     break;
Again, using the example above I get 4 instead of 20.

it sounds like it's dividing 3 / 49 and then adding 4 to the 0 it pushes back.

Edit: oh hey, I guess I should read more.


Yeah, I don't think I can help without seeing more code. how are you getting the values out of your linked list? what are the definitions for all of your operations? show me that code.
 

Magni

Member
Anyone with some Groovy/Grails experience here? I have a class project with some pretty strict guidelines to follow, specifically that I need to make a "Course" table in my database with a non-standard primary key. Instead of the default 'id: Integer' that is created automatically, I need a column called 'code' of type String.

Code:
class Course {

  String title

  static constraints = {
    title blank: false
  }
	
  static mapping = {
    version false
    id column: 'code', type: 'string', generator: 'assigned'
  }
}

This works fine, but then I can't save any objects I create:

Code:
def foo = new Course(title: "bar")
foo.save()
[B]org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be manually assigned before calling save()[/B]

def foo = new Course(title: "bar", code: "baz")
foo.save()
[B]org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be manually assigned before calling save()[/B]

def foo = new Course(title: "bar", id: "baz")
foo.save()
[B]org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be manually assigned before calling save()[/B]

I always get the same error, what am I doing wrong?

Finally found a fix!

Code:
class Course {

  [B]String id[/B]
  String title

  static constraints = {
    title blank: false
  }
	
  static mapping = {
    version false
    id column: 'code', type: 'string', generator: 'assigned'
  }

  [B]void setCode(String code) {
    id = code
  }

  String getCode() {
    return id
  }[/B]
}
 
it sounds like it's dividing 3 / 49 and then adding 4 to the 0 it pushes back.

Edit: oh hey, I guess I should read more.


Yeah, I don't think I can help without seeing more code. how are you getting the values out of your linked list? what are the definitions for all of your operations? show me that code.

I guess in the attempt to not put more than I need I've really dragged this out haven't I? I'll not make that mistake again.

This is the juicy bit of main. It's been reduced a tad but all the important bits should be there now.
Code:
struct values
{
	int num;
	struct values *next;
};

---------
	struct values *infoHead = '\0';
	struct values *infoTail;
	struct values *infoCounter;
---------
// Add to memory, calculate or print
	while( scanf( "%s", data ) != EOF )
	{
		if( ispunct( *data ) != 0 )
		{
			count = amountOfValues( infoHead );
			computeValues( data, infoHead, &infoCounter, count );
			infoTail = infoCounter;
			infoCounter = infoHead;
			continue;
		}
		else if( isdigit( *data ) != 0 )
		{
			listValues( data, &(infoTail->next) );
			infoTail = infoTail->next;
		}
		else if( *data == 'P' || *data == 'p' )
		{
			printf( "Expression = %d\n", infoTail->num );
		}
}

Function that puts values in the tail
Code:
void listValues( char *integer, struct values **info )
{
	struct values* current = (struct values*)malloc(sizeof(struct values));

	current->num = atoi(integer);
	current->next = *info;
	*info = current;
}

Computes and chops off tail
Code:
void computeValues( char *operator, struct values *info, struct values **refInfo, int count )
{
	int i;
	int first;
	int second;

	struct values* current = (struct values*)malloc(sizeof(struct values));
	struct values* replacement = (struct values*)malloc(sizeof(struct values));
	current = *refInfo;
	replacement = info;

	// Get values from nodes and check for enough values
	for( i = 1; i < count - 1; i++ )
	{
		replacement = replacement->next;
	}
	first = replacement->num;

	if( replacement->next == '\0' )
	{
		printf( "Error: Not enough operands. Quitting program.\n" );
		exit(1);
	}
	else
	{
		replacement = replacement->next;
		second = replacement->num;
	}

	for( i = 1; i < count - 1; i++ )
	{
		current = current->next;
	}

	//Compute expression
	switch( *operator )
	{
		case '+':
			first = first + second;
			current->num = first;
			current->next = '\0';
			break;

Thank you guys for being patient with me. I'm still learning!
 
Meeehhhh vector.erase() ruins everything by copying into a new resized container.

My needs for it make it run in O(n^2) instead of O(n). Meehhhh. No go.

edit: woot. iter_swap and pop_back() fixed that, now it runs closer to O(1);
 

Slavik81

Member
Meeehhhh vector.erase() ruins everything by copying into a new resized container.

My needs for it make it run in O(n^2) instead of O(n). Meehhhh. No go.

edit: woot. iter_swap and pop_back() fixed that, now it runs closer to O(1);

It sounds like you're manually implementing the erase-remove idiom.

EDIT: Though, if you're just talking about a single element, then nevermind.
 
Anyone with experience in Jquery? I'm working on my group project's front end and nothing comes out. Here's the basic syntax of the code. This is a competitive class so I won't ... post everything but here's the jist of it. Thanks!


Code:
$().ready(function () {
	$('.account_type').change(function() {
				var acctype = $('select.account_type').val();
				if(acctype=='project' || acctype == 'default') {
					$('.entrygroup_sql').fadeOut();
				}
				if (acctype=='project_mysql' || acctype == 'mysql_only') {
					$('.entrygroup_sql').fadeIn();
				}
			});
    // validate the comment form when it is submitted
    $("#commentForm").validate();

    // validate signup form on keyup and submit
    $("#signupForm").validate({
        rules: {
            account_type: "required",
            first_name: {
                required: true,
                lettersonly: true,
                minlength: 2
            },
            last_name: {
                required: true,
                lettersonly: true,
                minlength: 2
            },
            email_address: {
                required: true,
                email: true
            },
            phone_number: {
                required: true,
                digits: true,
                minlength: 2
            },
            account_name: {
                required: true,
                alphanumeric: true,
                minlength: 2
            },
            project_name: {
                required: true,
                lettersonly: true,
                minlength: 2
            },
            disk_quota: {
                required: true,
                digits: true,
                min: 1
            },
            major: "required",
            project_advisor: {
                required: true,
                lettersonly: true,
                minlength: 2
            },
            advisor_email: {
                required: true,
                email: true,
                minlength: 2
            },
            unix_shell: {
                required: true
            },
            num_participants: {
                required: true,
                digits: true,
                min: 1
            },
            database_location: {
                required: true
            },
            messages: {
                account_type: "Please select an account type",
                first_name: {
                    required: "First name is required",
                    lettersonly: "Letters only",
                    minlength: "Your username must consist of at least 2 characters"
                },
                last_name: {
                    required: "Last name is required",
                    lettersonly: "Letters only",
                    minlength: "Your username must consist of at least 2 characters"
                },
                email_address: {
                    required: "An Email address is required",
                    email: "Please enter a email address"
                },
                phone_number: {
                    required: "Please enter a phone number",
                    digits: "Please enter digits only",
                    minlength: "Your username must consist of at least 10 digits with areacode"
                },
                account_name: {
                    required: "Account name is required",
                    alphanumeric: "Alphanumeric please",
                    minlength: "Your username must consist of at least 1 characters"
                },
                project_name: {
                    required: "Project name is required",
                    lettersonly: "Letters only",
                    minlength: "Your username must consist of at least 1 characters"
                },
                disk_quota: {
                    required: "Disk Quota is required",
                    digits: "Please enter digits only",
                    min: "Please enter a number"
                },
                major: {
                    required: "Major is required"
                },
                project_advisor: {
                    required: "Project advisor is required",
                    lettersonly: "Letters only",
                    minlength: "Your username must consist of at least 1 characters"
                },
                advisor_email: {
                    required: "Project advisor email is required",
                    email: "Please enter a email address",
                    minlength: "Your username must consist of at least 1 characters"
                },
                unix_shell: {
                    required: "Unix shell is required"
                },
                num_participants: {
                    required: "Number of participants is required",
                    digits: "Please enter digits only",
                    min: "Please enter at least one participant"
                },
                database_location: {
                    required: "Please enter a database location"
                }
            }
        }
    });
});
 
^^ Long function is long. Would jquery allow you to break that up a bit? Might make it more obvious what's going wrong and where when you can see it in smaller, digestible, named chunks.
 

squidyj

Member
I guess in the attempt to not put more than I need I've really dragged this out haven't I? I'll not make that mistake again.

This is the juicy bit of main. It's been reduced a tad but all the important bits should be there now.


Thank you guys for being patient with me. I'm still learning!

- Is your prof teaching you to use structs and malloc like that in C++?
- Your computeValues function is cut off. I don't see where it removes elements from the list.
- what does this function do? what is the significance of the integer it returns? amountOfValues( infoHead );

I assume this is supposed to be the head of the linked list. *infoHead = '\0';
and this is supposed to be the tail*infoTail;
what, then, is this supposed to be? *infoCounter;

- It seems like what you're trying to do is, when you read in an operator, you walk to the end of the list to grab the last 2 elements, operate on them and store the result in the first of the two then discard the second at the tail.
- when you walk the list in those for loops it's kind of awkward to run from one to less than count - 1. you wind up looping count - 2 times. it's a lot more readable if you just return a count that's 2 smaller and run i = 0 to i < count. That is of course if you intend for a count of 5 to walk you forward 3 nodes in the list.

- are you forbidden from adding list elements more like a stack? in front of each-other instead of behind?
 

hateradio

The Most Dangerous Yes Man
^^ Long function is long. Would jquery allow you to break that up a bit? Might make it more obvious what's going wrong and where when you can see it in smaller, digestible, named chunks.
It's not really long; the longest part are validation rules, think of it like JSON.

Anyone with experience in Jquery? I'm working on my group project's front end and nothing comes out. Here's the basic syntax of the code. This is a competitive class so I won't ... post everything but here's the jist of it. Thanks!


Code:
$().ready(function () {
	$('.account_type').change(function() {
				var acctype = $('select.account_type').val();
				if(acctype=='project' || acctype == 'default') {
					$('.entrygroup_sql').fadeOut();
				}
				if (acctype=='project_mysql' || acctype == 'mysql_only') {
					$('.entrygroup_sql').fadeIn();
				}
			});
    // validate the comment form when it is submitted
    $("#commentForm").validate();

    // validate signup form on keyup and submit
    $("#signupForm").validate({ . . . });
});
I've never used validate, but you should change the first part from $().ready(function... to jQuery(function.... It's a bit cleaner.

As I said, I'm not familiar with validate, but what exactly isn't working?
 

APF

Member
Anyone with experience in Jquery? I'm working on my group project's front end and nothing comes out. Here's the basic syntax of the code. This is a competitive class so I won't ... post everything but here's the jist of it. Thanks!

There's just not enough information to debug or track down possible issues. Might also want to try breaking down the problem to isolated parts, in order to see what's actually working or not. Another good tactic is to put debug statements or breakpoints in the code, to see what's being called / what's in scope when it's called, etc.
 
The error checking, i.e letters only doesn't work. I'll break it down in a bit. Typing on a phone and in class.

But basically if i input numbers in first name, id want to be able to tell myself to input letters only. The rules are the conditions and the messages are the outputs if the rules aren't met. The only problem is that none of this works in the end and bad inputs are able to go through.

Jfiddle puts this as clean too.
 

Lkr

Member
just a few quick questions:
i have steadily gotten better at C++, and now I have to drop everything and switch to java. Is java that hard to transition to if I already understand the principles of OOP?
second, do you prefer C++ or java and why?

thanks
 

usea

Member
just a few quick questions:
i have steadily gotten better at C++, and now I have to drop everything and switch to java. Is java that hard to transition to if I already understand the principles of OOP?
second, do you prefer C++ or java and why?

thanks
Java is radically simpler. The switch shouldn't be very hard at all. It's a lot easier than going the other way.

I think java and c++ both have their uses. If I was going to solve something I could do in a single sitting, I'd prefer to use java by about 100x. You can get things done much more quickly. There are many languages I'd choose over java though.

If I was writing a game, or a general purpose library, or a command line tool, I'd use C++. But there are languages I'd choose before c++ for those tasks, too.

But the biggest factor is familiarity.

Java for C and C++ Programmers
Java for C++ Programmers
Wikipedia: Comparison of Java and C++ (syntax)
 
So the re-education (sounds evil) of Randolph Freelander (sounds third person) is continuing merrily along.

I am now relearning Calculus, which is something I have wanted to do for years. It's interesting how dumb it's making me feel. It has been umpteen years since I did math of this nature, and man am I rusty (which is why I'm relearning).

It's amazing. The first lecture video I watched from MIT's 18.01 (Single Variable Calculus - Fall 2006 [actually filmed in 2007... don't ask]) made me feel stupid while it was showing me something I already knew. Namely, finding derivatives of polynomials, for example. Like, dude arrived at the formula which I still remembered, but the math for arriving at that formula highlighted just how much I have forgotten over the years.

Fortunately, I've been through a couple more lecture videos this evening, and it's knocking some of the rust off.
 
- Is your prof teaching you to use structs and malloc like that in C++?
- Your computeValues function is cut off. I don't see where it removes elements from the list.
- what does this function do? what is the significance of the integer it returns? amountOfValues( infoHead );

I assume this is supposed to be the head of the linked list. *infoHead = '\0';
and this is supposed to be the tail*infoTail;
what, then, is this supposed to be? *infoCounter;

- It seems like what you're trying to do is, when you read in an operator, you walk to the end of the list to grab the last 2 elements, operate on them and store the result in the first of the two then discard the second at the tail.
- when you walk the list in those for loops it's kind of awkward to run from one to less than count - 1. you wind up looping count - 2 times. it's a lot more readable if you just return a count that's 2 smaller and run i = 0 to i < count. That is of course if you intend for a count of 5 to walk you forward 3 nodes in the list.

- are you forbidden from adding list elements more like a stack? in front of each-other instead of behind?

-Our class is winding down on C and moving on to C++. I'm currently writing it in C because I don't have a lot of time to be making syntax errors and I'm more comfortable with that.
-Crap. The rest of the function is just four more switch cases that do the exact same operation (subtraction, multiplication, division and modulus). By making the ->next pointer in the second to last node null aren't you removing the last node from the list itself?
-
Code:
int amountOfValues( struct values* head )
{
	int count = 0;
	struct values* counter = head;

	while( counter != '\0' )
	{
		count++;
		counter = counter->next;
	}

	return count;
}
It just rides the list and finds out how many values there currently are.
-infoCounter would be the duct tape I used to try and get the program up and running. I was encountering a problem where I would put infoHead into the compute function and the head pointer would remain at the tail of the list even after I tried to have it point back to the head. I used another pointer to ride down the list instead so infoHead would never move.
-That's correct (what I'm doing in compute). Good to know, I'll make sure to design my for loops a little cleaner next time.
-There's nothing forbidding me from putting nodes on the head instead of the tail. This way just made more sense to me so I did it this way.
 

Lkr

Member
Java is radically simpler. The switch shouldn't be very hard at all. It's a lot easier than going the other way.

I think java and c++ both have their uses. If I was going to solve something I could do in a single sitting, I'd prefer to use java by about 100x. You can get things done much more quickly. There are many languages I'd choose over java though.

If I was writing a game, or a general purpose library, or a command line tool, I'd use C++. But there are languages I'd choose before c++ for those tasks, too.

But the biggest factor is familiarity.

Java for C and C++ Programmers
Java for C++ Programmers
Wikipedia: Comparison of Java and C++ (syntax)

thanks for the links. i need to figure out how to define classes in java since everything is a class. i'm just so used to having my header files and cpp files
 
Is java that hard to transition to if I already understand the principles of OOP?
second, do you prefer C++ or java and why?

thanks

Nah. Java is strictly OOP though, whilst c++ is generally multi paradigm, (but mostly used for oop in my experience).

I prefer c++ because fuck Oracle... Seriously though, I'm stubborn and I really dislike java's verbosity (though its verbosity is understandable, I just don't like it for stupid reasons)

So the re-education (sounds evil) of Randolph Freelander (sounds third person) is continuing merrily along.

I am now relearning Calculus, which is something I have wanted to do for years. It's interesting how dumb it's making me feel. It has been umpteen years since I did math of this nature, and man am I rusty (which is why I'm relearning).

It's amazing. The first lecture video I watched from MIT's 18.01 (Single Variable Calculus - Fall 2006 [actually filmed in 2007... don't ask]) made me feel stupid while it was showing me something I already knew. Namely, finding derivatives of polynomials, for example. Like, dude arrived at the formula which I still remembered, but the math for arriving at that formula highlighted just how much I have forgotten over the years.

Fortunately, I've been through a couple more lecture videos this evening, and it's knocking some of the rust off.

Yeah. I've had some "holy shit that makes sense" moments with some of the discrete mathematics stuff that I wasn't quite firm on, as well as some of the Series stuff from Calculus 2, and some linear algebra stuff..

Hell I guess I realised I'm a practical person then..
 
^ My intention is to progress through single variable calculus, then move on to multiple variable calculus and beyond, which are levels that I never reached in college as they were not required for at my university for my degree (Info Sys, not Comp Sci). We did Calc and Statistics, and that's basically all that was required. And I've forgotten dern near all of it.
 

squidyj

Member
-Our class is winding down on C and moving on to C++. I'm currently writing it in C because I don't have a lot of time to be making syntax errors and I'm more comfortable with that.
-Crap. The rest of the function is just four more switch cases that do the exact same operation (subtraction, multiplication, division and modulus). By making the ->next pointer in the second to last node null aren't you removing the last node from the list itself?
-
Code:
int amountOfValues( struct values* head )
{
	int count = 0;
	struct values* counter = head;

	while( counter != '\0' )
	{
		count++;
		counter = counter->next;
	}

	return count;
}
It just rides the list and finds out how many values there currently are.
-infoCounter would be the duct tape I used to try and get the program up and running. I was encountering a problem where I would put infoHead into the compute function and the head pointer would remain at the tail of the list even after I tried to have it point back to the head. I used another pointer to ride down the list instead so infoHead would never move.
-That's correct (what I'm doing in compute). Good to know, I'll make sure to design my for loops a little cleaner next time.
-There's nothing forbidding me from putting nodes on the head instead of the tail. This way just made more sense to me so I did it this way.

Let me try to convince you to do it the other way. why? because that's a stack. you push your values on then you pop them off when you need them. The values you want to operate on will be at the front of the list, every time. you can pop them off when you want to work on them and push the result back on. You don't have to count off anything or walk through the list x steps or anything like that.

when you pop you just grab your number, then set the head to be whatever is next in the list. you only need to test if you're trying to pop off an empty list.

when you push, you just malloc a new entry, set it's next to the current head/top, and then set head/top to it. which is practically what you're doing at the tail of your list right now.

It might seem like it's harder to understand but I think you'll actually find it easier to debug because it winds up doing a lot less, if some part of it is broken it should be easier to find and fix. Anyways a stack is just like a stack of plates, you put a new plate on the top of the stack, or you take one off, you don't care about the bottom of the stack, you only ever interact with the top of the stack and then only need to know about what's next on the stack.

if you decide to make that change you would probably have to flip order on your subtract and divide.

The other thing is you use '\0' which I'm guessing is supposed to set the pointer to 0. It would again be more readable to use NULL instead and far more appropriate when dealing with pointers, it's not really intuitive for a pointer to have a value of a character. It's far more intuitive to have a null pointer.
 
Hi folks and folkettes,

I'm in need of some guidance here. I've scoured the internet (read: Google search results) for help, and I think the minds of this thread may be able to aid me better.

I'm wanting to install and begin to learn how to use OpenGL (specifically, JOGL). Can someone please give me a "for dummies" step-by-step guide for how to get it up and running in my IDE of choice? It may be best to assume I'm entirely clueless and know just the basic terminology (some of these tutorials I've been looking at are a bit over my head with the terms). I'm starting to feel like a big idiot because I can't figure this out.

Really I'm just looking for help in getting it working in my IDE. Any help would be greatly appreciated. Thanks so much in advance to anyone who can help!
 
So the re-education (sounds evil) of Randolph Freelander (sounds third person) is continuing merrily along.

I am now relearning Calculus, which is something I have wanted to do for years. It's interesting how dumb it's making me feel. It has been umpteen years since I did math of this nature, and man am I rusty (which is why I'm relearning).

It's amazing. The first lecture video I watched from MIT's 18.01 (Single Variable Calculus - Fall 2006 [actually filmed in 2007... don't ask]) made me feel stupid while it was showing me something I already knew. Namely, finding derivatives of polynomials, for example. Like, dude arrived at the formula which I still remembered, but the math for arriving at that formula highlighted just how much I have forgotten over the years.

Fortunately, I've been through a couple more lecture videos this evening, and it's knocking some of the rust off.

It's quite amazing how much more sense a lot of the things I "learned" in college make to me now. I reread through my old Data Structures book a few months ago in my quest to pull myself out of the sysadmin hole I've dug for myself in recent years and it's night and day.

Education is wasted on the young!
 
It's quite amazing how much more sense a lot of the things I "learned" in college make to me now. I reread through my old Data Structures book a few months ago in my quest to pull myself out of the sysadmin hole I've dug for myself in recent years and it's night and day.

Education is wasted on the young!

It sure is.
 
Just curious, in what context are you doing this assignment? I though postfix calculator is a classic stack application.

I'm not sure I understand what you mean by the context but it was supposed to be a stack assignment.

Our last assignment using linked lists, however, was a first in-first out scenario and I had added at the tail and removed from the head for that assignment. I figured since I already had an understanding of how that worked I would run with that and adjust accordingly for this assignment.
 

Chris R

Member
Just curious, in what context are you doing this assignment? I though postfix calculator is a classic stack application.

It is a classic stack application. The only two times I had to deal with a RPN calculator was once in my data structures class and one in assembly, both times using stacks to complete the assignment.
 

luoapp

Member
Our last assignment using linked lists, however, was a first in-first out scenario and I had added at the tail and removed from the head for that assignment. I figured since I already had an understanding of how that worked I would run with that and adjust accordingly for this assignment.

I was a little bit baffled when I didn't see the pop and push operations in your code, I thought you are working on some other topic ( like lexical analysis or something).
 

D4Danger

Unconfirmed Member
I've never used validate, but you should change the first part from $().ready(function... to jQuery(function.... It's a bit cleaner.

Nah, just do

Code:
$(function() {
    //Your stuff here
});

or put the javascript file at the bottom of the HTML file and then you don't have to wait for the dom

Also, I need help on doing alphanumeric, letters only validation. But progress. There's something at least.

regex maybe?
 
I was a little bit baffled when I didn't see the pop and push operations in your code, I thought you are working on some other topic ( like lexical analysis or something).

Is it recommended to use functions named "push" and "pop?" That's how our professor and material referred to them but I figured that was just used for instructional purposes.

*Edit*

Also, I've already changed the program and it works as intended. Guess doing it as a stack is a lot easier lol
 

Aleph

Member
Hi folks and folkettes,

I'm in need of some guidance here. I've scoured the internet (read: Google search results) for help, and I think the minds of this thread may be able to aid me better.

I'm wanting to install and begin to learn how to use OpenGL (specifically, JOGL). Can someone please give me a "for dummies" step-by-step guide for how to get it up and running in my IDE of choice? It may be best to assume I'm entirely clueless and know just the basic terminology (some of these tutorials I've been looking at are a bit over my head with the terms). I'm starting to feel like a big idiot because I can't figure this out.

Really I'm just looking for help in getting it working in my IDE. Any help would be greatly appreciated. Thanks so much in advance to anyone who can help!

Have you tried LWJGL? I personally tried learning how code with OpenGL using this library, but I couldn't find any good tutorials (setting up the project wasn't too hard, though. I was using Eclipse.). After trying that I moved to C++ OpenGL using Visual Studio and a bunch of OpenGL related libraries, luckily there are many good modern C++ tutorials for OGL.
 

luoapp

Member
Is it recommended to use functions named "push" and "pop?" That's how our professor and material referred to them but I figured that was just used for instructional purposes.

Well, that's the convention when people think about stack problems. Also, stack is a fundamental hardware data structure and almost all CPUs have push/pop assembly instruction (that's why rhfb mentioned assembly class), it's only beneficial you have a good understanding of it. IMHO, you should have a nice implementation of a stack class based on your linked list, independent from your RPN calculator. Just FYI, C++ has the stack container class derived from vector, deque and list classes.
 
Hi folks and folkettes,

I'm in need of some guidance here. I've scoured the internet (read: Google search results) for help, and I think the minds of this thread may be able to aid me better.

I'm wanting to install and begin to learn how to use OpenGL (specifically, JOGL). Can someone please give me a "for dummies" step-by-step guide for how to get it up and running in my IDE of choice? It may be best to assume I'm entirely clueless and know just the basic terminology (some of these tutorials I've been looking at are a bit over my head with the terms). I'm starting to feel like a big idiot because I can't figure this out.

Really I'm just looking for help in getting it working in my IDE. Any help would be greatly appreciated. Thanks so much in advance to anyone who can help!

Can't help you with jogl but usually most people recommend reading the opengl book, most people don't recommend the NeHe tutorials but are a good starting point IMHO, just take them with a grain of salt.
 
Well, that's the convention when people think about stack problems. Also, stack is a fundamental hardware data structure and almost all CPUs have push/pop assembly instruction (that's why rhfb mentioned assembly class), it's only beneficial you have a good understanding of it. IMHO, you should have a nice implementation of a stack class based on your linked list, independent from your RPN calculator. Just FYI, C++ has the stack container class derived from vector, deque and list classes.

Ok, good to know. Thank you as well!
 

Rapstah

Member
I have a file where I know the contents are a multiple of 32 bits long. What the contents are is not important, but I need to "pack" this file, so to speak, with a high start bit, eight bits of the file, and a low end bit, and put it into another file. This is eventually supposed to tell a communications port on something when segments of the file end, and there might be other programs after mine that assume this is how the file works. I'm programming it in C++. Naturally, as the contents of what I'm actually sending and getting don't matter, I open the source file and the result file as bit files. This is where I'm stuck:

Because the smallest amount of bits you can actually get from a file at a time in C++ is apparently the size of a char, two bytes, and the same rule applies for writing to a bit file, basic mathematics tell me I need to load two chars at a time (4 bytes = 32 bits) and pack them so I end up with 40 bits, or five bytes:

11111111 22222222 33333333 44444444
H1111111 1LH22222 222LH333 33333LH4 4444444L

This makes sense to me, and as mentioned I know the in file is in blocks at least this large, so the basic idea of generating this file should work out. The issue is turning the first row into the second row. Bit shifts are probably helpful if not essential, but bit shifts are only really helpful if I can address and write to the entire second 40-bit sequence in chunks of one bit. I don't see how this is possible and would love some help. I was at one point thinking about defining the second part as a 40-bit array of booleans and casting pointers to get parts of the first array into my intended spots of that one, followed by manually setting the high and low bits where I want them, but the internet makes it seem like boolean arrays don't really work this way.

If my assumptions at any point are wrong then please tell me so.
 

luoapp

Member
H1111111 1LH22222 222LH333 33333LH4 4444444L
=

((( ((((H x 256 + 11111111 ) x4+LH ) x 256 + 22222222 ) x4 + LH ) x 256 + 33333333 )x4 + LH ) x 256 + 44444444) x2+L)

A long integer should be able to hold all 40bits, and x256 can be replaced with <<8
 

Rapstah

Member
A char is actually just 1 byte, not 2.

Really? On all architectures? I might be getting my languages mixed up by assuming it's two. I totally remember doing x86 stack stuff by casting pointers to chars at some point in C so it obviously makes sense that chars are the same in C++.

H1111111 1LH22222 222LH333 33333LH4 4444444L
=

((( ((((H x 256 + 11111111 ) x4+LH ) x 256 + 22222222 ) x4 + LH ) x 256 + 33333333 )x4 + LH ) x 256 + 44444444) x2+L)

A long integer should be able to hold all 40bits, and x256 can be replaced with <<8
I'll use something very close to this, thanks. I thought I needed something exactly 40 bits in size but I can obviously just move 5 bytes at a time from the pointer and ignore the rest.
 

TheFatOne

Member
This isn't really a programming question, but I thought this would be the best place to ask. So I somehow lucked myself into an opportunity for an internship this upcoming summer. The only issue is I feel like I have zero chance of getting it. The last semester I have not been able to code at all, and have only really done the basic minimum to pass because I have been struggling in Physics and Calc. I feel wholly unprepared, and my programming skills are lacking. I feel like my programming skills have improved, but I am still not very good at it. Any general advice for someone in my situation? My interview is coming up sometime in the next couple of weeks, and I'm pretty sure I'm going to bomb :(
 

Kalnos

Banned
Really? On all architectures? I might be getting my languages mixed up by assuming it's two. I totally remember doing x86 stack stuff by casting pointers to chars at some point in C so it obviously makes sense that chars are the same in C++.

8 bits -> 2^8 = 256

Same size as standard ASCII table.
 

Slavik81

Member
Really? On all architectures? I might be getting my languages mixed up by assuming it's two. I totally remember doing x86 stack stuff by casting pointers to chars at some point in C so it obviously makes sense that chars are the same in C++.

A char is defined as 1 byte. Theoretically the number of bits in a byte can change depending on architecture (though that doesn't really happen these days). The CHAR_BIT macro will tell you that information.

Those casts you're talking about sound suspicious. The integer type for holding a pointer is uintptr_t. A char is almost certainly too small. Perhaps you mean you were casting from void* to char*?
 

Rapstah

Member
A char is defined as 1 byte. Theoretically the number of bits in a byte can change depending on architecture (though that doesn't really happen these days). The CHAR_BIT macro will tell you that information.

Those casts you're talking about sound suspicious. The integer type for holding a pointer is uintptr_t. A char is almost certainly too small. Perhaps you mean you were casting from void* to char*?

Yeah, sorry, I meant char pointers. Very different things.
 
Top Bottom