Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 30 Dec 2000
Offline Last Active Today, 11:45 AM

#5186522 where are the 4 addresses of an integer

Posted by nobodynews on 12 October 2014 - 12:01 PM

What language? Probably C or C++, but I don't like being a mind reader. I believe you are trying to ask how to get the memory address of each memory element (call it a byte) in an integer, assuming that integer uses 4 bytes to compose that integer. I say "assuming" because, although it is common for int to have a size of 4, it isn't guaranteed to be. Since this sounds like homework I'm afraid I'm not going to directly answer your question. Instead, I will point out that you should consider the address-of operator operator, '&'. Once you know the address of a variable, do you know how to get the following address of that int? It would be 4 bytes following, right? What if you had 'char n' , got the address, and then got the following address? It would be 1 byte following, right? Is there a way you can get the address of an int and treat it like you got the address of a char?


Hopefully by understanding the answer to the first question the answer to the second will be easier to comprehend and answer.

#5186519 how to redimensione (ReDim) an array in C++

Posted by nobodynews on 12 October 2014 - 11:50 AM

You don't; not directly. You use std::vector.

#5186517 Rotating point around point in 2D

Posted by nobodynews on 12 October 2014 - 11:45 AM


I take this opportunity to plug complex numbers


Are you using complex numbers because they happen to be a pair of floats/doubles, or is there something about complex numbers that make them well-suited to this use? I'm rather ignorant of math. How is typedef'ing a std::complex better than typedef'ing some other kind of two-float class?


If you look at rotate_around_center Alvaro utlized the properties of complex numbers to achieve the rotation. The only use of trig was in capturing the initial angle of rotation as a complex number. You may be interested the article AVisual, Intuitive Guide to Imaginary Numbers.

#5177046 SDL Memory Leak

Posted by nobodynews on 30 August 2014 - 05:45 AM

You have two calls to SDL_CreateTextureFromSurface but only one call to SDL_DestroyTexture.

#5171412 multiple source files and global varaibles.......................

Posted by nobodynews on 04 August 2014 - 09:10 AM

My problem is with my global variables which I was trained to utilize the most.

I'm curious what you mean by this. I've only heard train and globals used together when saying you should train yourself to not use them.

#5169646 Do GL and DX 'go through' the Windows GDI?

Posted by nobodynews on 27 July 2014 - 07:52 PM



In Windows Vista, all Windows applications including GDI and GDI+ applications run in the new compositing engine, Desktop Window Manager which is built atop the Windows Display Driver Model.




Direct3D 9Ex, Direct3D 10, and Direct3D 11 are only available for Windows Vista and newer because each of these new versions was built to depend upon the new Windows Display Driver Model that was introduced for Windows Vista


So, for at least Windows Vista and newer operating systems, GDI and DirectX are built on top of the Windows Display Driver Model, DirectX more directly. I'm not sure what Windows did before Vista, but I'm almost 100% certain DirectX bypassed GDI.

#5167522 C++ smart pointer usage

Posted by nobodynews on 17 July 2014 - 11:29 PM

I'm not sure what you did that 'broke all of [your] functions that had that vector being passed in', but you should be able to just pass in the std::vector of std::unique_ptrs as a reference. I tested it to be sure (and utilized typedefs; I'd suggest doing the same if you'd like fewer nested brackets):

#include <iostream>
#include <memory>
#include <vector>

class Planet
    int X;
    int Y;

typedef std::unique_ptr<Planet> Planet_ptr;
typedef std::vector<Planet_ptr> Planet_vctr;

void Function1(Planet_vctr &alteredVector)
    Planet_ptr p(new Planet);

    alteredVector.push_back( move(p) );

void Function2(const Planet_vctr &constVector)
    if (constVector.size())
        std::cout << "Not Empty!\n";
        std::cout << "Empty!\n";

int main() {
    Planet_vctr aVector;

Without delving into how you're using the pointers, I wouldn't be able to offer a suggestion on whether to use unique_ptr or shared_ptr. I found this explanation from Stack Overflowfairly coherent that might help you.

#5159360 remapping the keyboard (esp {} () )

Posted by nobodynews on 09 June 2014 - 04:39 PM

if you dont like to answer me dont answer not a problem, byt do not spamm me with useles and not interesting pseudo- philosophy

If you don't like the answers you get not a problem, but do not spam the boards with useless and not interesting pseudo-philosophy yourself. You could just as easily ignore answers that you don't like, but instead you're wasting your time arguing with people about how they shouldn't respond as they see fit because you want to ask questions as you see fit. IMO that's kind of hypocritical of you.

#5148617 Need help with installation of program

Posted by nobodynews on 21 April 2014 - 04:15 PM


I didn't even think about the permissions. I was having the installer put it into the program files folder in the windows directory. Could I perhaps have the program write to the public folder in users? If so would the following statement be correct?:


What you really want to do is query windows for the appropriate path to use. Look into using the function SHGetKnownFolderPath with a KNOWNFOLDERID of "FOLDERID_Documents". Then you'll for sure use the correct path for each user instead of hoping its what you expect.

#5147742 How to stop users from manipulating Game Save Data

Posted by nobodynews on 17 April 2014 - 04:00 PM

Does it mean to parse each character of the textfile to be a 1 or a 0?

It does not mean that. It means instead of having a text file you write the data in machine-readable form instead of humanly readable form. Consider, say, a .jpg file. That is an example of a binary file. I'm not a java programmer, but I found a small tutorial on how to do binary file i/o here that might help you.

#5147659 What's the point of floats in C?

Posted by nobodynews on 17 April 2014 - 09:34 AM

You must have read something that was about variadoc parameters, e.g. printf. That only applies to functions that can take an arbitrary number of parameters. Normal functions don't do that unless the function specifically says to use doubles. An explanation for why is here. The other thing you might be confused about is how the literal 0.0 is a double. If you want a float literal you have to specifiy 0.0f. I don't know why the language design went with double as default over float as default for literals.

#5147435 c++ oo syntax behind the scenes behavior

Posted by nobodynews on 16 April 2014 - 12:58 PM

fascinating! i thought local declarations did a new in the background and a dispose on return, using the heap.

Things only go on the heap if they are explicitly allocated, either directly or indirectly. If the object you create on the stack uses allocation with new, then that data would go on the heap. The pointer to that data would be on the stack. If the object you created was on the heap then both the pointer and the other data would both go on the heap. Its basically recursive. Say you created an object on the heap and called a member function. If that member function has local variables then they would be pushed onto the stack even though the object itself was allocated on the heap. This is due to the way the compiler treats executable code.

would object1 go on the stack when main was called? or is main a special case and it goes in the data segment?
main is exactly like any other function except it is called by the operating system rather than your program.

object1 (its member var storage space) would go in the data segment?
That would go in the data segment. While I said that main is a special case, it's slightly more complicated than I implied. main is actually called indirectly by the operating system in most environments. The operating system will generally call a function implemented in the run-time library. You can read a little about it here. That link mentions that the run-time library will initialize global variables before main is called. If the operating system called main directly then none of the constructors for the global variables would be called, among other things.

#5147399 How to stop users from manipulating Game Save Data

Posted by nobodynews on 16 April 2014 - 11:18 AM

Who's more entitled? The person who wants to use something they bought the way they want to use it or the person that doesn't let someone use the product the way they want to use it?

#5142973 Help to understand my own misstake?

Posted by nobodynews on 28 March 2014 - 07:57 PM



std::map::at takes a key, not an index. What your first try was actually accomplishing was returning the value associated with key=0. In the words of that reference:


std::out_of_range if the container does not have an element with the specified key


You didn't have key=0 in your std::map hence that exception. std::map::begin, however, returns an iterator to the first std::pair in the std::map container. The key isn't used at all. As long as there is one item in your std::map the iterator method will work.

#5141142 Is hatred for unity justified?

Posted by nobodynews on 21 March 2014 - 07:28 PM

So, what games has your professor made?