• 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

EDIT: fixed error 1.

VHDL question:




2) error line 73: incompatible types for arithmetic operator: LHS=std_logic_vector!37, RHS=std_logic_vector!40
3)error line 78: incompatible types for arithmetic operator: LHS=std_logic_vector!49, RHS=std_logic_vector!52

I have no clue why 2 and 3 are errors, I'm just adding two std_logic_vectors together.

From what I remember from class you can't just add 2 logic vectors together using a standard arithmetic operator (+). You have to use a full adder port map. You should be including ieee.numeric as well. I think the reason that you can't simply add them is http://www.cs.sfu.ca/~ggbaker/reference/std_logic/arith/arith.html. According to this link VHDL can't determine wether vector is signed or unsigned unless specified.
 

usea

Member
Can anyone tell me how to fix this problem? I'm trying to change my XNA code so that bomb placement is synced between windowed and full screen:

Code:
		public void generateLightBombs(List<BaseObject> list)
		{
			Player player = (Player)list[0];
			Vector2 playerPosition = player.mPosition;
			[B]Vector2 direction = new Vector2(Mouse.GetState().X - 400, Mouse.GetState().Y - 240);[/B]
			direction.Normalize();

			if(0 < player.Bomb && Keyboard.GetState().IsKeyDown(Keys.B) && pressedKey.IsKeyUp(Keys.B))
			{
				list.Add(new LightBomb(Color.Yellow, new Rectangle((int)(playerPosition.X - direction.X * 100.0f), 
(int)(playerPosition.Y - direction.Y * 1000.0f), 10, 10)));
				player.Bomb--;
			}
			pressedKey = Keyboard.GetState();
		}

I assume the bolded is the problem with the hard coded numbers and I'm supposed to connect the viewport size somehow? I basically want the bombs my space ships drop to always end up behind the ship at a fixed distance no matter what direction the ship is facing (which depends on where the mouse cursor is).
I don't see how the size of the screen comes into play (except scaling the distance behind the ship the bombs drop maybe).

You want to get a position that is N pixels on the other side of the ship from the mouse cursor. So get a vector from the ship, away from the mouse cursor. Normalize it. Then multiply by the distance you want the bombs to be. Then add it to the ship's position.

Is the ship always in the center of the screen? That would be why the code you pasted works the way it does. It does basically what I said, except instead of getting a vector from the ship, it gets a vector from 400, 240. Replace those numbers with the ship's position, and also consider fiddling with the 100.0f and 1000.0f in the following line. They're saying how far from the ship to put the bomb.
Code:
list.Add(new LightBomb(Color.Yellow, new Rectangle((int)(playerPosition.X - direction.X * 100.0f), (int)(playerPosition.Y - direction.Y * 1000.0f), 10, 10)));

I could be totally wrong though.
 

Bruiserk

Member
From what I remember from class you can't just add 2 logic vectors together using a standard arithmetic operator (+). You have to use a full adder port map.

Edit: Actually have you tried including ieee.numeric_std and leaving your code as is?

This worked. I don't know if my Professor is okay with it, but I'll email him. Now I can move on to the second part of the assignment, thanks a bunch dude.
 
This worked. I don't know if my Professor is okay with it, but I'll email him. Now I can move on to the second part of the assignment, thanks a bunch dude.

Great! No prob! Your professor should definitely be okay with it unless he is a total idiot. ieee.numeric_std is industry standard library. As you can see arithmetic library is very backwards and inflexible that its incapable of doing standard addition without being very specific about signed/unsigned or literally using a full adder component.
 

Minamu

Member
I don't see how the size of the screen comes into play (except scaling the distance behind the ship the bombs drop maybe).

You want to get a position that is N pixels on the other side of the ship from the mouse cursor. So get a vector from the ship, away from the mouse cursor. Normalize it. Then multiply by the distance you want the bombs to be. Then add it to the ship's position.

Is the ship always in the center of the screen? That would be why the code you pasted works the way it does. It does basically what I said, except instead of getting a vector from the ship, it gets a vector from 400, 240. Replace those numbers with the ship's position, and also consider fiddling with the 100.0f and 1000.0f in the following line. They're saying how far from the ship to put the bomb.
Code:
list.Add(new LightBomb(Color.Yellow, new Rectangle((int)(playerPosition.X - direction.X * 100.0f), (int)(playerPosition.Y - direction.Y * 1000.0f), 10, 10)));

I could be totally wrong though.
Alright, I'll look into that. It's not exactly my code, it's from last weekend's game jam, so I don't really know what their line of thought was. We had similar issues with our text hud but that solution wasn't portable line by line but I suppose that code should give some hints (I think it went something like *something* - graphics.GraphicsDevice.Viewport.Width / 2 to make sure the text is always centered etc).
 

usea

Member
Alright, I'll look into that. It's not exactly my code, it's from last weekend's game jam, so I don't really know what their line of thought was. We had similar issues with our text hud but that solution wasn't portable line by line but I suppose that code should give some hints (I think it went something like *something* - graphics.GraphicsDevice.Viewport.Width / 2 to make sure the text is always centered etc).
That would be a way to get the middle of the screen. But you want to place bombs according to the ship's position, not based on the middle of the screen.
 

Mew2

Neo Member
Any recommendations on some good basic programming sites? Preferable to Java...I know it isn't C but ;]
 
I'm extremely new to programming, so you have to explain this very... low.


The final cout is highlighted with red, I'm assuming that is were the error is with my debug. The program is supposed to calculate the area of a triangle.

Anyone got some help? I've been googling a few of the step ups and choose this one.

When I debug and try to boot it up, it says "System can not find file specified"

The line in question (the last cout) has an end1. This should be endl, as in the letter L, for end line. That's where your error is arising. What others have pointed out about your code may well be valid, but that endl issue is what's generating the error that's causing that particular line to highlight red.
 

Jayhawk

Member
Everything seemed fine when I last looked at it but I think I should give it another look.

I don't think #include lines for the libraries are enough in Xcode. You need to add the GLUT and OpenGL libraries to your project (i.e., drag and drop the shit into your project's file hierarchy). You can also add the OpenGL frameworks to your project, but I am too tired at this point to remember how.
 

Jayhawk

Member
I forgot to include the glkit framework >_>

I hope that fixed the linking issue.

Regarding jokkir's coding problem from the previous page with a random string being separated by new line characters and such... Is there a reason why you can't use the strtok function with '\n' as the delimiter or pushing the string into a stream and the available getline functions for a stream?
 

Jokab

Member
I'm studying Software Engineering (half of year 1 done) and so far we've been using Java for everything. I had next to no programming experience prior to starting the program, so I don't really know anything else. However, I'm considering slowly learning some other language on my own, what would you guys recommend? I was eyeing Python at http://learnpythonthehardway.org.
 

mannerbot

Member
I'm studying Software Engineering (half of year 1 done) and so far we've been using Java for everything. I had next to no programming experience prior to starting the program, so I don't really know anything else. However, I'm considering slowly learning some other language on my own, what would you guys recommend? I was eyeing Python at http://learnpythonthehardway.org.

Check out edX's 6.00x or Udacity's CS101 for Python and edX's CS50x for C. LPTHW is good too though.
 
I'm studying Software Engineering (half of year 1 done) and so far we've been using Java for everything. I had next to no programming experience prior to starting the program, so I don't really know anything else. However, I'm considering slowly learning some other language on my own, what would you guys recommend? I was eyeing Python at http://learnpythonthehardway.org.

LPTHW is good, but skip the last few chapters. It just goes overboard with concepts and exercises imo. After you've gone through that book you can do the recommendations given by Mannerbot, or go through a book like Think Python. Some of it will be a rehearsal of things already explained by LPTHW, but it goes beyond that pretty fast.

Some other decent books for a beginner might be Python Core Programming by Wesley Chun (which uses python 2.6 or 3.0) or Practical Programming: An Introduction to Computer Science Using Python Pragmatic Programmers (which uses python 2.5).
 

Zeppelin

Member
I'm studying Software Engineering (half of year 1 done) and so far we've been using Java for everything. I had next to no programming experience prior to starting the program, so I don't really know anything else. However, I'm considering slowly learning some other language on my own, what would you guys recommend? I was eyeing Python at http://learnpythonthehardway.org.

C. You'll learn a lot more from learning C than you will from learning Python, especially if you're coming from Java.
 
I'm learning xml and on the assignment I am doing I have come to a road block.

I have to calculate the total number of shares processed for each individual. I've tried various XPath functions to get the correct numbers(246 and 300) but I keep on failing. With the functions I've tried I either get the total number(546) between the two or I get zero. Any help would be appreciated

XML
Code:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="invest.xslt"?>
<!-- Data file for Assignment 1 -->

<accounts>
  <account>
    <id>10000011</id>
    <name>Smith, John</name>
    <investment ticker="AMC">
      <transaction type="buy">
        <date>03/20/2010</date>
        <price>45.00</price>
        <numShares>78</numShares>
      </transaction>
      <transaction type="buy">
        <date>03/22/2010</date>
        <price>42.00</price>
        <numShares>53</numShares>
      </transaction>
      <transaction type="sell">
        <date>08/5/2010</date>
        <price>47.00</price>
        <numShares>115</numShares>
      </transaction>
    </investment> 
    <investment ticker="DMX">    
      <transaction type="buy">
        <date>01/20/2010</date>
        <price>35.00</price>
        <numShares>100</numShares>
      </transaction>   
      <transaction type="buy">
        <date>02/22/2010</date>
        <price>37.00</price>
        <numShares>50</numShares>
      </transaction>      
      <transaction type="sell">
        <date>01/5/2011</date>
        <price>42.00</price>
        <numShares>150</numShares>
      </transaction>    
    </investment>
  </account>
</accounts>


XSLT
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/">
      <hmtl>
        <head>
          <title>Investments</title>
        </head>
        <body>
          <h1>Investment Account</h1>
          <xsl:apply-templates select="accounts/account" />
        </body>
      </hmtl>
    </xsl:template>


  <xsl:template match="account">
    <table border="1" cellpadding="1" cellspaceing="0">
    <tr>
      <td>
        <b>ID</b>
      </td>
      <td>
        <b>Name</b>
      </td>
    </tr>
    <tr>
      <td>
        <xsl:value-of select="id"/>
      </td>
        <td>
        <xsl:value-of select="name"/>
      </td>
    </tr>
    <xsl:for-each select="investment" >
      <tr> 
        <td>
        <b>Transaction For Investment <xsl:value-of select="@ticker"/>:</b>
      </td>
      </tr>
      <tr>
        <td>Date</td>
        <td>Price</td>
        <td>Shares</td>
        <td>Value</td>
        <tr>
          <td>
            <xsl:apply-templates select="transaction"/>
          </td>
        </tr>
      </tr>

  <!--<tr>
        <td>

          Total Processed:<xsl:value-of select="sum(//numShares[@ticker])"/>
        </td>

      </tr>-->
</xsl:for-each>
</table>
</xsl:template>

  <xsl:template match="transaction">
    <table>
      <td>
        <xsl:for-each select="date" >
          <td>
            <xsl:value-of select="." />
          </td>
        </xsl:for-each>
      </td>
      <td>
        <xsl:for-each select="price" >
          <td>
            <xsl:value-of select="." />
          </td>
        </xsl:for-each>
      </td>
      <td>
        <xsl:for-each select="numShares" >
          <td>
            <xsl:value-of select="." />
          </td>
        </xsl:for-each>
      </td>
      <td><xsl:value-of select="price * numShares" />
      </td>
    </table>
  </xsl:template>

  <!--<xsl:template match="totalShares">
    Total Shares: <xsl:value-of select="sum(/transaction/numShares)"/>
  </xsl:template>-->
  
  <!--<xsl:template match="totalShares">
  <xsl:for-each select="/" >
    <tr>
      <td>
        <b>
          <xsl:value-of select="accounts/account/investment/@ticker/transaction"/>
          Total Processed:<xsl:value-of select="sum(numShares)"/>
        </b>
      </td>
    </tr>
  </xsl:for-each>
  </xsl:template>-->
</xsl:stylesheet>
 

jimi_dini

Member
I'm studying Software Engineering (half of year 1 done) and so far we've been using Java for everything. I had next to no programming experience prior to starting the program, so I don't really know anything else. However, I'm considering slowly learning some other language on my own, what would you guys recommend? I was eyeing Python at http://learnpythonthehardway.org.

If you want to learn a really great scripting language, try REXX.

There is also an open source interpreter for REXX available called Regina REXX, so it's available for almost all platforms. http://regina-rexx.sourceforge.net/

The best thing about that language, is that you can easily extend the language using DLLs. It also has the ingenious command "parse value".
 
I'm studying Software Engineering (half of year 1 done) and so far we've been using Java for everything. I had next to no programming experience prior to starting the program, so I don't really know anything else. However, I'm considering slowly learning some other language on my own, what would you guys recommend? I was eyeing Python at http://learnpythonthehardway.org.

Python is a great alternative, go for it.
 

mltplkxr

Member
I'm studying Software Engineering (half of year 1 done) and so far we've been using Java for everything. I had next to no programming experience prior to starting the program, so I don't really know anything else. However, I'm considering slowly learning some other language on my own, what would you guys recommend? I was eyeing Python at http://learnpythonthehardway.org.

Since you're still in school, check out one of the new functional languages like Scala, Clojure, even Lisp. It'll introduce you to think about, and solve, problems in a completely different way. Or javascript.
 

mltplkxr

Member
^ Scala isn't exclusively functional, it's also fundamentally OO.

Thanks for pointing it out, it is a great point to make. And that's kinda why I suggested it.
But honestly, I haven't touched those yet. So I'm kind of talking through my hat. I was scarred for life while learning functional languages back in Uni.
(I had a mad scientist kind of teacher who thought us FP in a very abstract and mathematical way, with the added bonus of errors in his exercises. But it's the good kind of scar ;)
 

BreakyBoy

o_O @_@ O_o
I can vouch for Scala being a great bridge language to go from OO to functional programming. I kind of hated it at first, but in the last few months it's really growing on me.

Also, if you're coming from a Java background, that will help a bit with learning Scala as well.
 
Java question, I'm getting a NullPointerException error and struggling to see where I'm going wrong here.

Basically I have to create an employee records thing and I'm adding these employees to an array then one by one displaying the ....
Snip...

In the console Jane's information is displayed but the first 2 just return null and I can't see why.

I just had to point out that this is not the way to ask for help. You're using java. Use the eclipse debugger. Use breakpoints and step through your code. Youll see when the exception occurs and then you can dig deeper into the offending classes code.

Alternatively, go into your main and comment out all function calls and object initializations (basically all of the code) and start adding a few lines at a time. Once you see the exceptions starting again, you now know which class the problem is in. Then you look at everything that is getting called here and start doin print statements or single stepping in the debugger.

Posting 100+ lines of code here won't help you in the long run when learning how to debug and fix code will become increasingly important.

Learning how to use debuggers is probably one of the single biggest increases in productivity that new programmers can see. I know guys that still in their 3rd year of comp sci avoid debuggers and it's painful.


Also, to the software engineer looking for new languages: you're already doing java so I wouldn't bother with c# (not right now anyways. It's important to learn for jobs and such later on though) since its very similar to java.

The way I see it you have three (real) alternatives. Either learn c or c++ if you want to work very close to the metal and learn how computers actually work a bit more, or go for a higher level of abstraction and go with lisp/scheme (and use the very famous sicp book, just google it. It's free) OR you could go with a language like python. Any one of those would be worth learning.
 
Btw, I wasnt stating people shouldn't ask for help. They should just make an effort to narrow it down and then once they've narrowed it down to a section of code, it they still can't see the issue then post that bit. It will not only illicit more responses, but half the time if they use the steps I outlined above they will solve it themselves.
 

Minamu

Member
That would be a way to get the middle of the screen. But you want to place bombs according to the ship's position, not based on the middle of the screen.
Code:
		public void generateLightBombs(List<BaseObject> list)
		{
			Player player = (Player)list[0];
			Vector2 playerPosition = player.mPosition;
			[B]Vector2 direction = new Vector2(Mouse.GetState().X - BaseObject.Viewport.Width / 2, 
							Mouse.GetState().Y - BaseObject.Viewport.Height / 2);[/B]
			direction.Normalize();

			if(0 < player.Bomb && Keyboard.GetState().IsKeyDown(Keys.B) && pressedKey.IsKeyUp(Keys.B))
			{
				list.Add(new LightBomb(Color.Yellow, new Rectangle((int)(playerPosition.X - direction.X * 100.0f), 
							(int)(playerPosition.Y - direction.Y * 100.0f), 10, 10)));
				player.Bomb--;
			}
			pressedKey = Keyboard.GetState();
		}
Perhaps not exactly what you told me, but this seems to work. One of my team mates fixed it and didn't tell me. I also had 1000.0f instead of 100.0f on the Y axis and that screwed things up a lot.
 

Exuro

Member
Alright first programming class in a year and I've pretty much forgotten how to program.

Was told to make a matrix adt and I'm having trouble with a function I made. I'm getting

"incompatible types when assigning to type 'matrix' from type 'int' "

on the function call in the second block.

Code:
//This is the function itself which is fine/what the prof wants.  It creates a matrix and assigns the values of a T(double)* array I think.
matrix create_initvals(int rdim, int cdim, T* initval) 
{
	matrix result;
	result.row_dim = rdim; 
	result.col_dim = cdim;
	result.element = (T*)malloc(rdim * cdim * sizeof(T));
	for (int i = 0; i < rdim; i++)
		for (int j = 0; j < cdim; j++)
			result.element[i * cdim + j] = 
				*initval;
	return result;

}

Code:
//Made a matrix a, int ROWS and COLS and T* array(which is just a double) with all elements 0
matrix a;

a = create_initvals(ROWS, COLS, array);

I'm not sure where the "from type int" is coming from.

EDIT: So I made variable a into an int for kicks and the error goes away... Pretty confused as to why it thinks the function create_initvals is of type int. Can I not set structs equal to other structs or something?
 

Yeef

Member
I suppose this place is probably the best place to ask.

I'm plenty good at actual programming, but it's all self-taught so I don't know much project management. I'm looking for resources on stuff like versioning, best practices for varible and file names and that sort of thing. Can anyone point me in the right direction?
 

Slavik81

Member
I suppose this place is probably the best place to ask.

I'm plenty good at actual programming, but it's all self-taught so I don't know much project management. I'm looking for resources on stuff like versioning, best practices for varible and file names and that sort of thing. Can anyone point me in the right direction?

Naming conventions vary per language. How version control is done varies among companies and among version control systems.

What are you building, and what languages or 3rd-party code will you be using?

Alright first programming class in a year and I've pretty much forgotten how to program.

Was told to make a matrix adt and I'm having trouble with a function I made. I'm getting

"incompatible types when assigning to type 'matrix' from type 'int' "

on the function call in the second block.

<snip>

I'm not sure where the "from type int" is coming from.

EDIT: So I made variable a into an int for kicks and the error goes away... Pretty confused as to why it thinks the function create_initvals is of type int. Can I not set structs equal to other structs or something?

Odd that it went away. My guess is that the forward declaration for the function is wrong. In any case, the problem isn't in that snippet... though where's the template<class T> for your create_initvals? I'm presuming it does exist in your actual code, since you should receive a different error if it did not.

EDIT: And no, a struct of one type can be assigned to a struct of the same type, unless you wrote code that specifically disallowed that. You'd see a different error if assigning the struct were disallowed.
 

usea

Member
I've been doing some network programming which is supposed to be pretty simple. However, here are some dumb mistakes I made today.

1) When using Array.Copy(source, destination, amount) in C# to get a sub-array, copying an array to itself won't actually shrink the array. Make a new one...

2) Can't get your program to talk to itself over the network? Check windows firewall. Still won't work? Check windows firewall again. Lost an hour because the program I was hosting my code in had a rule in the firewall blocking it from the network.

3) Getting an error message when trying to receive data with the UdpClient class that reads something like "the connection was forcibly reset" even though UDP is connection-less? You're likely trying to send to a destination that is not reachable, and the response telling you this is being blocked by windows. So when you try to receive on the same binding, you finally see the error.
 

Yeef

Member
Naming conventions vary per language. How version control is done varies among companies and among version control systems.

What are you building, and what languages or 3rd-party code will you be using?
Not building anything in particular. I'm more interested in the broad strokes of the philosophies. Everything I've done in the past has just been small, personal projects, but I realize that there's some habits I'll need to break and some structural things I'll need to know if I ever do decide to work on a project with other people.

I figured in practice specifics would depend on the specific environment, but I was hoping there was some resource out there with more general information.
 

Slavik81

Member
Is there any way to prevent Kaspersky antivirus from ruining your Windows C++ build? I've recently had to deal with this virus of a program and even with almost everything disabled, workspace paths excluded from scanning, and as many build programs as possible marked as trusted, it still increases my build times by about 10-20x... and they're nearly an hour long to begin with.

Not building anything in particular. I'm more interested in the broad strokes of the philosophies. Everything I've done in the past has just been small, personal projects, but I realize that there's some habits I'll need to break and some structural things I'll need to know if I ever do decide to work on a project with other people.

I figured in practice specifics would depend on the specific environment, but I was hoping there was some resource out there with more general information.

Well, I could just point you to how Google does it. I should warn you they do some things very, very differently from other software development companies. Though, admittedly, the same could be said of nearly every software development company.
 

Exuro

Member
Odd that it went away. My guess is that the forward declaration for the function is wrong. In any case, the problem isn't in that snippet... though where's the template<class T> for your create_initvals? I'm presuming it does exist in your actual code, since you should receive a different error if it did not.

EDIT: And no, a struct of one type can be assigned to a struct of the same type, unless you wrote code that specifically disallowed that. You'd see a different error if assigning the struct were disallowed.
Alright Here's the code. It's set up as matrix.h, matrix.c and test.c.



Code:
//matrix.h

#ifndef MATRIX_H
#define MATRIX_H

typedef double T;
typedef struct {
int row_dim;
int col_dim;
 T* element;
 } matrix;

#endif

Code:
//matrix.c
#include"MATRIX.h"
#include<stdlib.h>

matrix create_empty(int rdim, int cdim) {
	matrix result;
	result.row_dim = rdim;
	result.col_dim = cdim;
	
	for (int i = 0; i < rdim; i++)
	{
		for(int j = 0; j < cdim; j++)
		{
			result.element[i * cdim + j] = 0;
		}
	}
	
	return result;

}

matrix create_initvals(int rdim, int cdim, T* initval) {
	matrix result;
	int five = 5;
	result.row_dim = rdim; 
	result.col_dim = cdim;
	result.element = (T*)malloc(rdim * cdim * sizeof(T));

	for (int i = 0; i < rdim; i++)
		for (int j = 0; j < cdim; j++)
			result.element[i * cdim + j] = *initval;
	return result;
}

void destroy_matrix(matrix m){
free(m.element);
}

Code:
//test.c
#include"MATRIX.h"
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
int COLS = 12;
int ROWS = 10;
T* array;

array = (T*)malloc(ROWS * COLS * sizeof(T));

for (int n=0; n<COLS*ROWS; n++) {
	array[n] = 0;
	}

matrix a;

a = create_initvals(ROWS, COLS, array);

destroy_matrix(a);

return 0;
}

So the error is coming from a = create... on test.c, but is because its recognizing the function as an int for some reason. What I'm wanting it to do is take the values from the array which for now are just 0 and pass them to the matrix, but the int error, no idea what is the cause of that. The matrix is supposed to be set up as a dynamic matrix. I'm going to guess it's how I set up my struct or something.
 
Alright Here's the code. It's set up as matrix.h, matrix.c and test.c.



Code:
//matrix.h

#ifndef MATRIX_H
#define MATRIX_H

typedef double T;
typedef struct {
int row_dim;
int col_dim;
 T* element;
 } matrix;

#endif

So the error is coming from a = create... on test.c, but is because its recognizing the function as an int for some reason. What I'm wanting it to do is take the values from the array which for now are just 0 and pass them to the matrix, but the int error, no idea what is the cause of that. The matrix is supposed to be set up as a dynamic matrix. I'm going to guess it's how I set up my struct or something.

No prototype yo. You need to declare the prototype in MATRIX.h otherwise it doesnt know what create... is supposed to generate and defaults to int.
 

gblues

Banned
exuro said:
Code:
void destroy_matrix(matrix m){
  free(m.element);
}

This is a crash bug waiting to happen. A more robust function would look like this:

Code:
void destroy_matrix(matrix m) {
  if(m && m.element != NULL) // this check prevents a crash if you accidentally try to destroy the same matrix twice
  {
    free(m.element);
    m.element = NULL;
  }
}
 

PriitV

Member
So I have this method, but for the life of me I can't figure out how to repaint my JFrame within this method.
Code:
    public void startTimer(){
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
//            @Override
            public void run(){
                if(state >=0 && state<3){state++;}
                else if(state==3){state=-1;}
            }
        }, 
        2*1000,
        2*1000);
    }
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Why do people use non-typed Arrays argarhgargharghargh.

THERE ARE GENERIC COLLECTIONS RIGHT THERE.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Looking at the code. The goal is to be written in pure c so generic collections are out.

Oh sorry no, that outburst was regarding a project I'm working on.

It's written in Unityscript (Unity's flavor of Javascript) and it has an dynamic Array class that is not typed.

And there's about 38 warnings related to implicit downcasting because anything retrieved from those Arrays are treated as Object.

I don't know whether to leave them alone or turn all of them into List<T>.
 

Lathentar

Looking for Pants
This is a crash bug waiting to happen. A more robust function would look like this:

Code:
void destroy_matrix(matrix m) {
  if(m && m.element != NULL) // this check prevents a crash if you accidentally try to destroy the same matrix twice
  {
    free(m.element);
    m.element = NULL;
  }
}

He also has a memory leak as array is never freed. This is in addition to the create empty function which will overwrite random memory values with 0.
 
I have an Android problem.

I have a 2 spinners.

One of the spinners holds the general section: Upper Body/Lower Body/Feet

The other one holds the specific body part dependant on what the other spinner chose: Head/Neck Torso/Chest/Abdomen

Currently that is working fine: I use an OnClickListener so when you choose the first spinner option it fills the other spinner with the right values.

I save the users choice.

Problem: Loading. When I want to load the saved choice I can't get the spinner to select the second spinner value. First I call
((Spinner) findViewById(R.id.mySpinner)).setSelection(firstpos);
Which chooses the right selection on the first spinner. And then I call
((Spinner) findViewById(R.id.mySpinnerDetail)).setSelection(secpos);
But this one seems to be overwritten/is executed too late, and the spinner doesn't change selections (always shows first item).

What I am looking for:
A way to force the second spinner to wait for the first spinner to fill it's values and then make the selection
 
Top Bottom