Jump to content


Check out our Community Blogs

ZekeDragon

Member Since 29 Jul 2009
Offline Last Active May 21 2017 04:37 PM
-----

#611450 A Short Eulogy to Dennis Ritchie

Posted by ZekeDragon on 16 October 2011 - 08:41 AM

Not since Nokola Tesla has such profound genius come, and now passed, so unrecognized. Dennis Ritchie was an inspiration, a visionary, and has permanently influenced the way every one of us as software developers, hobbyists and engineers work. While the world mourns for a salesman, the programming pantheon has lost one of it's brightest stars, without whom we may never have had the most frequently used language and influential operating system ever written.

I've never been any good at these things, and I'm loathe to the fact that I never had the opportunity to know him personally, but unavoidably my life has been touched by Dennis Ritchie. Nearly all of the software technology I use today has been influenced by Dennis Ritchie's creations, be it all the software I use and write in C, the C-syntax languages like C++, Java, and Go, the UNIX-like operating system, or any application and library written to work with these languages or systems. Under appreciated brilliance has been lost, but it is my sincere hope that we do not lose everything that Dennis has given us.

It is rare indeed to find such unfettered passion and deep knowledge even from those who have so shaped the world of computer science as can be found in Dennis Ritchie. Without this treasure of a man, the infrastructure that builds our entire modern software world would be non-existent or dramatically inferior. Any more words would only be a disservice, so all that's left to say is: Dennis, you will be missed, and rest in peace.
  • 1


#608338 Function pointer problem

Posted by ZekeDragon on 28 August 2011 - 01:42 PM

Okay, you don't quite understand function pointers. A function pointer does not declare anything close to a function prototype, however a function prototype does allow you to get the address of that function, which you can assign to a function pointer.
#include <stdio.h>

void handler( int );

void (*pHandler) ( int ) = &handler;

int main( void )
{
  return 0;
}

void handler( int num )
{
  puts( "Handler Executed." );
}
This will build correctly. Also, why are you trying to catch SIGSTOP, you can't catch SIGSTOP nor SIGKILL, it's a fruitless endeavor. You can see the signal mechanism working in this implementation using SIGALRM.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>


void handler( int );


void (*pHandler) ( int ) = &handler;


int main( void )
{
  signal( SIGALRM, pHandler );
  alarm(5);
  while (1) putchar(getchar());
  return 0;
}


void handler( int num )
{
  puts( "Handler Executed!" );
  exit(0);
}
A function pointer does not declare or even imply a function, simply that a set of data that represents an address in memory to a function with the type signature provided in the type declaration exists. You must provide a separate function prototype to imply the existence of a similarly named function in the future, and that the function will have an address to link to at compile time.
  • 1


#607087 Closing wrapped stream objects

Posted by ZekeDragon on 11 August 2011 - 09:09 PM

close() automatically closes all inner streams, this allows you to make chained streams with temporary objects.
Citation
  • 2


#606300 Gaming Company domain needed

Posted by ZekeDragon on 02 August 2011 - 05:48 AM

I'd say you may be worrying too much about the name. I contend that it doesn't necessarily have to be some one-word combination of two ideas that sounds catchy, take Black Isle Studios for example (the guys who made Fallout and Baldur's Gate) or Santa Cruz Games (named after the city they're based in).

A name is something important, I would suppose, but I think that it's suitable to have just a name that sounds good for now that you can grow with. If at worst you hate the name, you can always change it later.

How about "Gemini Jazz Entertainment"? :P
  • 1


#603917 Is it possible to pass arrays by value to a function in c++?

Posted by ZekeDragon on 29 June 2011 - 05:12 AM

If you have an array, the only practical way to "pass by value" is to manually copy the array, or use an object that wraps the array and produces copies of the data when passed as a value (such as std::vector).
  • -1


#597022 C++ SDL problems

Posted by ZekeDragon on 16 April 2011 - 06:05 AM

so you can be aware that I just want it to work before I will waste time commenting more code that might not work.

This is completely the wrong way to go about writing code comments, at least in my opinion. I write code comments while I'm writing the code, usually before even writing it, so that I know what the code was intended to do and possibly how you intend on it doing that. The point of the comments is to clarify parts of code that may not have a distinct purpose from the names and usage alone.

As far as the problem goes, this looks like you missed calling SDL_Init(), which if you had, will result in Access Violations. Check and make sure you've called SDL_Init() before the SDL_DisplayFormat() function.

Also, you never SDL_FreeSurface() the fileoptimized Surface before returning the normal one if colorkey != true. And despite only returning the standard surface, this method will create two SDL Surfaces even if colorkey == false, which it shouldn't.
  • -1


#596411 The escape sequence \?

Posted by ZekeDragon on 08 April 2011 - 03:59 PM

Because of trigraphs.

#include <iostream>
using std::cout;
using sdt::endl;

int main()
{
  cout << "What's the difference?\?!" << endl;
  cout << "What's the difference??!" << endl;
  return 0;
}

What's the difference??!
What's the difference|
Note: GCC ignores trigraphs by default. If you need to use them in GCC, you'll need to use the -trigraph flag.
  • -1


#594064 Noob here, help!

Posted by ZekeDragon on 14 March 2011 - 01:24 AM

An instance method is a method that is associated with the instance of a particular class, namely the methods that can accept using the this reference. A "static" method and a "class" method are more-or-less the same thing, as they are methods for the entire class itself. The same goes for variables, and the simple way to think of access is that instances clearly have access to static class values (methods and objects), whereas static methods do NOT have access to a particular instance unless a reference to an instance is passed. Consider the following source code:
public class Main
{
    // This static int is accessible from any Main object or derivative:
    protected static int count;

    // This int is accessible by any Main instance, but it's associated to a particular Main instance.
    private int instanceVal;

    static
    {
        // This is a "Static initializer block", which you can think of as a constructor for the Class
        // object rather than a constructor for a particular instance of a Class.
        count = 0;
    }

    public Main(int val)
    {
        ++count; // Access the static int instance.
        instanceVal = val;
        // Remember that this assignment implicitly resolves to:
        // this.instanceVal = val;
        // and that "this" resolves to the particular instance of Main you're targeting.
    }

    // The main method happens to be a static method, so I saw no reason to write
    // another one to explain static methods. This method does NOT need an instance
    // of Main to run, so you could very simply just call Main.main(null) instead of
    // calling it on a particular instance.
    public static void main(String[] args)
    {
        Main first = new Main(10);
        Main second = new Main(20);

        // A static method of a class may access static values in that class:
        System.out.println("Current number of Main instances: " + count);

        // But it may not access instance variables directly, it must choose
        // an instance! The following won't compile:
        // instanceVal = 10;

        // Each instance of Main has a different value for instanceVal, take a
        // look:
        System.out.println("Values of instanceVal: " + first.instanceVal + 
                                                 " " + second.instanceVal);
    }
}
This is how Java treats static and instance methods/values. If there are any other questions don't hesitate to ask.
  • 1


#593646 Im new in java, SOMEBODY PLEASE HELP ME :(

Posted by ZekeDragon on 10 March 2011 - 02:52 AM

Do you know how to add an ActionListener to your JButton? You'll need to do that in order to get this to work. Adding an ActionListener is easy, just use the addActionListener method on your JButton.
ActionListener myListener = new MyActionListenerDerivitive();
myJButton.addActionListener(myListener);

  • 3


#593599 Weird STL map error

Posted by ZekeDragon on 09 March 2011 - 04:06 PM

Did you declare your HTTPServer as const? If you did you'll have to provide an overloaded version of operator[] for const that doesn't allow modifications to the references.
  • 1


#593285 Maximum nested cycles?

Posted by ZekeDragon on 06 March 2011 - 05:07 AM

g[m] = x[i]*x[j]*x[k]*x[l]*x[o]*x[q];
You never initialized m in your loop, did you initialize that value beforehand? If you didn't, it may be a random (negative!) value, and give you an access error on your array.

Also, this huge if statement:
if((i<j && j<k && k<l && l<o && o<q) && (i!=j && j!=k && k!=l && l!=o && o!=q) && (i!=j || i!=k || i!=l || i!=o || i!=q || j!=k || j!=l || j!=o || j!=q || k!=l || k!=o || k!=q || l!=o || l!=q))
Is mostly unnecessary. Consider your first set of parens:
(i<j && j<k && k<l && l<o && o<q)
If these all return true, then each condition you check afterward must also return true, since inherently if it's true that i < j then it must be true that i != j. The same principle holds for each other value, so that means all your program is going to do is check each values inequality a second time, then perform another i != j calculation, and when that returns true the whole thing will short circuit and the rest of the checks won't be made.

Just do this:
if(i<j && j<k && k<l && l<o && o<q)
That's fine.
  • 1


#592850 Sorting Values from Arrays

Posted by ZekeDragon on 01 March 2011 - 02:29 AM

Uhh... you never actually add input as a value into array:
for(int count=0; count<array.length; count++){
    		System.out.println("Enter the value for array index: " + count);
    		input = in.nextInt();
     		array[count] = input;
    	}
That should make it so it's no longer all 0's.
  • -1


#591714 Field size and constant value problem

Posted by ZekeDragon on 18 February 2011 - 09:46 AM

I think this is allowed in newer compilers, you just need to make n a constant. (Note that once constant has value you cannot change it)

const int n;
cin >> n;
int array[n];


You need to initialize "n"...

const int n = 0;


Heed what Flying Dutchman has said! cin >> n is bound to compile fail if n is const.

Variadic size arrays in older compilers are best accomplished simply using dynamic allocation, in my opinion.
  • 1


#591545 assert problem

Posted by ZekeDragon on 16 February 2011 - 08:30 AM

Did you make sure to tell your interpreter to not ignore assert statements? Remember that since the assert statement was not added until 1.4, the Java interpreter can still run into a lot of code that doesn't utilize asserts at all. As such, you have to give the Java interpreter a flag to signify the .class file uses asserts:
java -ea MyClassFile
That'll make it work. I tested this with OpenJDK on Ubuntu 10.10.

EDIT: wim dc already got this, gave NetBeans instructions too. I'm too used to using a text editor + command line. XD
  • -1


#591392 Java Run-Error in MenuBar Program

Posted by ZekeDragon on 14 February 2011 - 06:28 PM

u Tell me how do i mention a Line no. in This type of Error

Sure thing, this is simply an issue of learning how to read a stack trace. It's important to learn to read these as you will most likely encounter a lot of them in your programming career. :)

The first thing to look for is any bottom level or custom package level classes in the stack, or more bluntly, a class that you wrote. Here's the only two frames on the stack that you programmed:
Posted Image
The top one is ran in the Menu2 object's constructor, line 45 of Menus1.java. That is this line of code:
f.add (i2);
The real problem in your code is that you accidentally assigned i3 twice instead of assigning i2 and then i3, see here:
i3 = new MenuItem ("Open"); 
        i3 = new MenuItem ("Save");
But this stack trace would be crucial to determine what had happened, and it should get you to look at your f and i2 initialization.
  • 1




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download