Results 1 to 10 of 14

Thread: [C] The lousy random question thread

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    Quote Originally Posted by kung foo man View Post
    The function is used as callback, so it's nice to explicitly set the calling convention. But since its stdcall (=standard calling convention), its not really needed.

    Every big "project" defines there own types like DWORD (WinAPI) for "unsigned int". I suggest you use just the plain "unsigned int", so you dont depend on windows-include-files.
    Okay, i guess its better to stay on these conventions, since they are only for callbacks (at least for me now)

    EDIT: i solved the next after looking over it for some minutes ;D
    Code:
    	resFileLumpHandler_sp lpLumpHandler = lumpHandlerListPtr , lpTemp;	// Delete the lump handler list.
    	// is the same as:
    	resFileLumpHandler_sp lpLumpHandler = lumpHandlerListPtr;	// Delete the lump handler list.
    	resFileLumpHandler_sp lpTemp;	// Delete the lump handler list.
    Last edited by serthy; 9th June 2013 at 14:52.

  2. #2
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts

    [C++] methods excurs

    Hey, its me again..

    PHP Code:
    type foobar()
    {
        return (
    type)1337;
    }

    class 
    myClass
    {
        public:
            
    type x;

            
    type foobarfloat value )
            {
                
    type t value 2;
                
    std::cout << "type foobar( float value )" << std::endl;
                return 
    t;
            }

            
    void foobarfloat value )
            {
                
    value;
                
    std::cout << "void foobar( float value )" << std::endl;
            }
    };

    float tmp;
    myClass c1 c2;

    foobar(); //calls function but returnvalue isnt used
    tmp c1.foobar42 );//calls methods
    c2.foobar42 ); //does the compiler use the method without a returnvalue? 
    i know that the compiler generates different function-identifiers for both methods (different in and output types)

    but my question is: does the compiler/cpu know when to use a method with or without the returnvalue?



    EDIT
    maybe these console prints will brigthen things up
    Last edited by serthy; 2nd August 2013 at 21:04.

  3. #3
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    What stops you from doing that simple test? ^^
    timescale 0.01

  4. #4
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    not having a compiler atm xD

    (edited the question above)


    EDIT:
    http://www.compileonline.com/compile_cpp_online.php
    main.cpp:21:10: error: 'void myClass::foobar(float)' cannot be overloaded
    main.cpp:14:13: error: with 'myClass myClass::foobar(float)'
    Code:
    #include <iostream>
    
    bool foobar( float x )
    {
        std::cout << "" << std::endl;
        return true;
    }
    
    class myClass
    {
        public:
    
        myClass foobar( float x )
        {
            std::cout << "myClass foobar()" << std::endl;
    
            return myClass();
        }
    
        void foobar( float x )
        {
            std::cout << "void foobar()" << std::endl;
    
        }
    };
    
    int main( int argC , char* args[] )
    {
        myClass c1 , c2 , c3;
    
        foobar( 0.0f );
        c1.foobar( 0.0f );
        c2 = c3.foobar( 0.0f );
    }
    Last edited by serthy; 2nd August 2013 at 21:13.

  5. The Following User Says Thank You to serthy For This Useful Post:

    kung foo man (2nd August 2013)

  6. #5
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    next 'problem':

    i've got a struct including an array
    this array should be variable in its length , but <= MAX_LENGTH

    PHP Code:
    #define MAX_LENGTH 256

    struct myStruct
    {
        
    int array[MAX_LENGTH];
    }; 
    infact this struct is now filled with 256 unused integers
    how do i get anything similar to this without having a big empty array?

    EDIT:
    and i dont want to allocate new memory for every single input
    so neither 'int* array;' nor 'int array[];' will work without that and without using static construction like: 'struct myStruct s = { 1 , 2 , 3 };'
    Last edited by serthy; 15th August 2013 at 20:27.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •