• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Programming Thread

Status
Not open for further replies.

mr. ck

कुछ मीठा हो जाये
  • 308
    Posts
    14
    Years
    Can GNU MP library do it?

    I still don't understand what they mean by multi-precision...
     

    twocows

    The not-so-black cat of ill omen
  • 4,307
    Posts
    15
    Years
    Can GNU MP library do it?

    I still don't understand what they mean by multi-precision...
    It means it can hold as many decimal places as you want it to.

    I'm not sure if it would work, it's certainly something I'll look into. This page (linked from the Wikipedia page about GNU MP) also looks promising.
     

    mr. ck

    कुछ मीठा हो जाये
  • 308
    Posts
    14
    Years
    It means it can hold as many decimal places as you want it to.

    I'm not sure if it would work, it's certainly something I'll look into. This page (linked from the Wikipedia page about GNU MP) also looks promising.
    Seems promising :)
    I'll check it out too and try to make it work...

    It's just that, implementing such things on your own is an interesting task, that's why I was interesting in trying it out :P

    EDIT:
    We had this competition at a school, and the questions were horribly ripped off from SPOJ... There was one to calculate 100! and display it accurately. I remember seeing so many people defining their factorial functions to return long long long long long long long ...
    Those were some really weird questions (4 programs) for high school level to be done in 1.5 hours...
     
    Last edited:

    twocows

    The not-so-black cat of ill omen
  • 4,307
    Posts
    15
    Years
    Do any of you have a basic code template for a style switcher? I haven't been able to make one for some reason...
    Please reply with a VM/PM, though
    If you mean for the forums or something, you should ask in the Web subforum. If you mean like for an OS, I think that's a bit more complicated, you'd be better off looking for open source projects.
     

    mr. ck

    कुछ मीठा हो जाये
  • 308
    Posts
    14
    Years
    Does anyone know OpenGL, DirectX or XNA... or has ever wanted to program games or done that in C++?
     

    Chad -

     
  • 687
    Posts
    14
    Years
    • Seen Aug 27, 2012
    Is anybody here familiar with ActionScript? I know it's similar to Java, but I think it is limited(?). So, is it worth learning? Note that I'm aiming for website development and such. Are JavaScript or PHP better choices than AS? (I think they are different?)

    I already know C++ and have an intermediate understanding in Python and Ruby. Is that enough?

    (Sorry for too many questions..)

    Chad -
     

    mr. ck

    कुछ मीठा हो जाये
  • 308
    Posts
    14
    Years
    ActionScript is the thing with Flash, right? Yup it's worth learning... You can create dynamic applications with Flash and AS is useful for it.

    PHP is a different thing, it becomes almost a necessity when considering dynamic web pages... Say when you want to take user input, handle logins etc (PHP is almost like programming combined with web-pages)... It is generally preferred over Flash for the same job (comparability + speed)

    Combine Flash and PHP, and you can really good applications.

    Python with CGI and Ruby on rails can do the same jobs as PHP. C++ can do the job but I recommend against it.

    I say forget PHP, get a host with Ruby or Python with CGI and learn AS. Ruby on rails is almost exactly like Ruby.
     

    Chad -

     
  • 687
    Posts
    14
    Years
    • Seen Aug 27, 2012
    ActionScript is the thing with Flash, right? Yup it's worth learning... You can create dynamic applications with Flash and AS is useful for it.

    PHP is a different thing, it becomes almost a necessary when considering dynamic web pages... Say when you want to take user input, handle logins etc (PHP is almost like programming combined with web-pages)... It is generally preferred over Flash for the same job (comparability + speed)

    Python with CGI and Ruby on rails can do the same jobs as PHP. C++ can do the job but I recommend against it.

    I say forget PHP, get a host with Ruby or Python with CGI and learn AS. Ruby on rails is almost exactly like Ruby.

    Okay. Thanks for the answer. I will take your advice.

    Last question,

    In software development, C++ is still the best to use, right? Although there are many people who use and are now using the .NET framework (C# mainly). I didn't like C# much. I know it resembles C++ with a few added features, but I see it very based on Java (which I hate). So, my real question is that is it smart to keep using C++ or do I have to eventually shift to .NET?

    Thank you.

    Chad -
     

    twocows

    The not-so-black cat of ill omen
  • 4,307
    Posts
    15
    Years
    Okay. Thanks for the answer. I will take your advice.

    Last question,

    In software development, C++ is still the best to use, right? Although there are many people who use and are now using the .NET framework (C# mainly). I didn't like C# much. I know it resembles C++ with a few added features, but I see it very based on Java (which I hate). So, my real question is that is it smart to keep using C++ or do I have to eventually shift to .NET?

    Thank you.

    Chad -
    C# is great for quickly making applications, especially GUI ones. It's similar to Java but actually compiles to executable instead of .class and has sane gui-making stuff rather than Swing (which is horrible). Neither is really better, each has its own strengths, like with most programming languages.

    Also, it might be a good idea to learn C, it'll teach you a lot about how things actually work in the computer.
     

    mr. ck

    कुछ मीठा हो जाये
  • 308
    Posts
    14
    Years
    I'll just add... C# is good and easy... But nothing beats C/++.

    I learned it out of boredom, and I did like it, though I still use C++ for almost everything :)
     

    Chad -

     
  • 687
    Posts
    14
    Years
    • Seen Aug 27, 2012
    C++ question:

    How to pass an array index to a function?

    Consider this: (Just a simple example)

    Code:
    ...
    void function(int a, int b)
    {
         int myArray[a][b];
    }
    
    int main()
    {
         int one, two;
         
         cout << "Enter one: ";
         cin >> one;
    
         cout << "Enter two: ";
         cin >> two;
    
         function(one, two);
    
         return 0;
    }
    When I do this, errors like "non-constant expression as array bound" and others show. I know an array must hold a constant size. I tried pointers and dynamic allocation, but no good. Is there a way around this? I think it is something stupid.. O.o
     

    mr. ck

    कुछ मीठा हो जाये
  • 308
    Posts
    14
    Years
    Look into new[];

    You can't declare an array like int myArray[a]; The a and b part should be a whole number (constant)... Instead do something like:

    Code:
    int** myArray;
    myArray = new int*[a];
    for(int i = 0; i < a; ++i)
        myArray[i] = new int[b];
    This does the trick...This defines myArray as a pointer to an array of pointers. Then you allocate memory into each pointer in the array. It is technically not the same as a 2D array.
    You could easily create a 1D array using the statement: int* myArray = new int[a*b];
    EDIT: Also don't forget, everytime you do new[], you need to do a delete[] on the variable after it is used up...
    So you must do this for a 1D array:
    delete myArray;

    and this for the 2D one

    Code:
    for(int i = 0; i < a; ++i)
        delete myArray[i];
    delete myArray;
     
    Last edited:

    Chad -

     
  • 687
    Posts
    14
    Years
    • Seen Aug 27, 2012
    This actually worked! Thank you very much for this. I am now reading a tutorial on it.

    One question about the delete. The delete deletes the memory (address) the pointer points to, not the pointer itself, right? So, when using dynamically allocated memory (new), I have to end it with delete. What if I wanted to re-use a piece of code I previously deleted its memory and function? Are there cases were I may not use the delete keyword? OR does it re-allocate on its own when new is encountered? Note that I want it to stay at the same address. If it does re-allocate, it looses its memory location (I.E its address), right?

    Example
    :

    Say, myPointer was stored in address 0x08FF8000. When you use delete, myPointer looses its memory location. If it re-allocates, it does not store itself again in the same address, right? I want to use the address (0x08FF8000). I don't want it to be stored in another location.

    I hope this makes any sense, because somehow to me, it doesn't a lot. Lol.
     
    Last edited:

    twocows

    The not-so-black cat of ill omen
  • 4,307
    Posts
    15
    Years
    This actually worked! Thank you very much for this. I am now reading a tutorial on it.

    One question about the delete. The delete deletes the memory (address) the pointer points to, not the pointer itself, right? So, when using dynamically allocated memory (new), I have to end it with delete. What if I wanted to re-use a piece of code I previously deleted its memory and function? Are there cases were I may not use the delete keyword? OR does it re-allocate on its own when new is encountered? Note that I want it to stay at the same address. If it does re-allocate, it looses its memory location (I.E its address), right?

    Example
    :

    Say, myPointer was stored in address 0x08FF8000. When you use delete, myPointer looses its memory location. If it re-allocates, it does not store itself again in the same address, right? I want to use the address (0x08FF8000). I don't want it to be stored in another location.

    I hope this makes any sense, because somehow to me, it doesn't a lot. Lol.
    Correct. If it's anything like malloc in C, new returns a memory address that points to some free space, which you're setting myPointer equal to. It won't necessarily be the same space. If you don't want it to use a different address, don't delete it until later on.
     

    Chad -

     
  • 687
    Posts
    14
    Years
    • Seen Aug 27, 2012
    Okay thanks for the confirmation, twocows. xD I get it now.
     

    mr. ck

    कुछ मीठा हो जाये
  • 308
    Posts
    14
    Years
    Correct. If it's anything like malloc in C, new returns a memory address that points to some free space, which you're setting myPointer equal to. It won't necessarily be the same space. If you don't want it to use a different address, don't delete it until later on.
    twocows is right... new[] and delete[] are like malloc() and free().

    Also don't forget... Unlike 2D arrays, the memory is not continuous... Like for int nums[2][3]
    Memory would hold nums[0][0], nums[0][1], nums[0][2], nums[1][0], nums[1][1], nums[1][2] in the order continuously...
    But since you call new[] for every element in the int**, every element may not be together... ie, the values are not continuous.

    This would only matter in a few cases, but meh, just telling you.
     

    Chad -

     
  • 687
    Posts
    14
    Years
    • Seen Aug 27, 2012
    twocows is right... new[] and delete[] are like malloc() and free().

    Also don't forget... Unlike 2D arrays, the memory is not continuous... Like for int nums[2][3]
    Memory would hold nums[0][0], nums[0][1], nums[0][2], nums[1][0], nums[1][1], nums[1][2] in the order continuously...
    But since you call new[] for every element in the int**, every element may not be together... ie, the values are not continuous.

    This would only matter in a few cases, but meh, just telling you.

    Lol. I actually saw that somewhere. Anyways, thanks for the info., again. You've helped me a lot.

    Okay. Another question.

    Suppose a pointer is holding the address of a dynamically allocated memory. If we re-assign this pointer to another value's address, does it cause memory leaks?

    Code:
    int myValue = 10;
    int *myPointer = new int;      
    myPointer = &myValue          // address of myValue (&)

    And, since DAM has no scope, it needs to be deallocated (delete). If we didn't use delete, can it result in memory leakage?

    Thank you.
     
    Status
    Not open for further replies.
    Back
    Top