Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Martins Mozeiko

Member Since 11 Sep 2005
Online Last Active Today, 08:28 PM
-----

#5052341 Bizarre placement new[] operator return address

Posted by Martins Mozeiko on 11 April 2013 - 11:16 PM

I don't think that casting from void* to A* will change address. Cating from B* to A* - yes it can, but not from void*.


I think in this case author is allocating memory with new [] and array allocation stores length in first 4 bytes, that's why it returns address with +4 offset.




#5048671 How to statically link OpenAL-Soft for VC++

Posted by Martins Mozeiko on 31 March 2013 - 02:17 PM

but according to this post, I should be fine.

The information in link is a bit incorrect.

 

LGPL requires (from http://www.gnu.org/copyleft/lesser.html):

d) Do one of the following:

  • 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
  • 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.

So you are required to provide sources of your app, so users can link to different implementation of OpenAL library. Or you are required to use shared library when linking to OpenAL.




#5036483 What is the purpose of std::array?

Posted by Martins Mozeiko on 25 February 2013 - 04:18 PM

Try passing int a[10] to a function and getting its size wink.png
 

 

You mean like this?

 

template <class T, int N>
void printSizeOfArray(const T (&)[N])
{
    std::cout << N << std::endl;
}



#5033860 Is this a GCC bug or I am doing something wrong

Posted by Martins Mozeiko on 18 February 2013 - 01:12 PM

You should always post full error message instead of one line. For example "g++ -std=c++11 shows me following":

 

 

a.cpp: In instantiation of 'mfml::Matrix<DATA_TYPE, INT_TYPE, DATA_CONTAINER>::Matrix(mfml::Matrix<DATA_TYPE, INT_TYPE, DATA_CONTAINER>&&) [with DATA_TYPE = double; INT_TYPE = long unsigned int; DATA_CONTAINER = mfml::MatrixMatrixElementWiseOperation<double, long unsigned int, mfml::DataContainer<double, long unsigned int>, mfml::meta::plus<double>, mfml::DataContainer<double, long unsigned int> >]':
a.cpp:326:241:   required from 'mfml::Matrix<DATA_TYPE, INT_TYPE, mfml::MatrixMatrixElementWiseOperation<DATA_TYPE, INT_TYPE, Lhs, mfml::meta::plus<DATA_TYPE>, Rhs> > mfml::operator+(const mfml::Matrix<DATA_TYPE, INT_TYPE, Lhs>&, const mfml::Matrix<DATA_TYPE, INT_TYPE, Rhs>&) [with DATA_TYPE = double; INT_TYPE = long unsigned int; Lhs = mfml::DataContainer<double, long unsigned int>; Rhs = mfml::DataContainer<double, long unsigned int>]'
a.cpp:338:9:   required from here
a.cpp:165:107: error: no matching function for call to 'mfml::MatrixMatrixElementWiseOperation<double, long unsigned int, mfml::DataContainer<double, long unsigned int>, mfml::meta::plus<double>, mfml::DataContainer<double, long unsigned int> >::MatrixMatrixElementWiseOperation()'
a.cpp:165:107: note: candidates are:
a.cpp:299:19: note: mfml::MatrixMatrixElementWiseOperation<DATA_TYPE, INT_TYPE, Lhs, Op, Rhs>::MatrixMatrixElementWiseOperation(const Lhs&, const Rhs&) [with DATA_TYPE = double; INT_TYPE = long unsigned int; Lhs = mfml::DataContainer<double, long unsigned int>; Op = mfml::meta::plus<double>; Rhs = mfml::DataContainer<double, long unsigned int>]
a.cpp:299:19: note:   candidate expects 2 arguments, 0 provided
a.cpp:296:12: note: constexpr mfml::MatrixMatrixElementWiseOperation<double, long unsigned int, mfml::DataContainer<double, long unsigned int>, mfml::meta::plus<double>, mfml::DataContainer<double, long unsigned int> >::MatrixMatrixElementWiseOperation(const mfml::MatrixMatrixElementWiseOperation<double, long unsigned int, mfml::DataContainer<double, long unsigned int>, mfml::meta::plus<double>, mfml::DataContainer<double, long unsigned int> >&)
a.cpp:296:12: note:   candidate expects 1 argument, 0 provided 

 

As you can see it doesn't find following member:

 

error: no matching function for call to 'mfml::MatrixMatrixElementWiseOperation<double, long unsigned int, mfml::DataContainer<double, long unsigned int>, mfml::meta::plus<double>, mfml::DataContainer<double, long unsigned int> >::MatrixMatrixElementWiseOperation()' 

Why?

 

Your Matrix class has following move constructor:

 

    template <class DATA_TYPE,class INT_TYPE,class DATA_CONTAINER>
    inline Matrix<DATA_TYPE,INT_TYPE,DATA_CONTAINER>::Matrix(Matrix<DATA_TYPE,INT_TYPE,DATA_CONTAINER> &&M)
    {
       std::cout<<"move ctr"<<std::endl;
       dc.Data=NULL;
       dc.Rows=0;
       dc.Cols=0;
       std::swap(dc.Data,M.dc.Data);
       std::swap(dc.Rows,M.dc.Rows);
       std::swap(dc.Cols,M.dc.Cols);
    }
 

Which uses default constructor for dc member.

 

In operator + you are instantiating following class "Matrix<DATA_TYPE, INT_TYPE, MatrixMatrixElementWiseOperation<...> >".
So DATA_CONTAINER type will be "MatrixMatrixElementWiseOperation<...>", but it doesn't have default constructor! That's why compiler complains about template instantiation in operator +.
 
You should use std::move in move constructor:
    template <class DATA_TYPE,class INT_TYPE,class DATA_CONTAINER>
    inline Matrix<DATA_TYPE,INT_TYPE,DATA_CONTAINER>::Matrix(Matrix<DATA_TYPE,INT_TYPE,DATA_CONTAINER> &&M)
        : dc(std::move(M.dc))
    {
    }

 

 




#5032845 Why won't this C code compile?

Posted by Martins Mozeiko on 15 February 2013 - 05:22 PM

Variable definitions inside case must be in some scope.

Like this:

 

case RUNNING:
{ // <---- note the new scope
    unsigned char data;
    ...
}
 
case SAMPLING:
...



#5015999 [SOLVED] Query Devices in D3D11

Posted by Martins Mozeiko on 31 December 2012 - 01:21 AM

You should check that EnumAdapters1 returns S_OK.
Also you should check that GetDesc1 return S_OK.
If they don't return S_OK, then their error return code should hint where the problem lies - Get Desc1 expects pointer to existing structure, not NULL. It write to the object passed, but if you pass NULL there's nowhere to write adapter properties.

So you should write:

DXGI_ADAPTER_DESC1 temp_desc;
if (FAILED(adapter_ptr->GetDesc1(&temp_desc)) { error }

@NewDisplayName: nullptr is now standard way in C++11 how to say NULL.


#5010762 NULL vs 0

Posted by Martins Mozeiko on 14 December 2012 - 04:34 PM

SiCrane - I don't think it's true.
GCC (also Visual Studio) defines NULL like this: "#define NULL ((void *)0)" in stddef.h.
So:
c:\ test>type a.cpp

#define NULL ((void*)0)
void foo(int);
void foo(void*);
int main()
{
  foo(NULL);
}

c:\ test>g++ a.cpp
C:\Users\XXX\AppData\Local\Temp\ccAUKoxR.o:a.cpp:(.text+0x16): undefined reference to `foo(void*)'
collect2.exe: error: ld returned 1 exit status

foo(NULL) correctly calls foo(void*).


#5010711 NULL vs 0

Posted by Martins Mozeiko on 14 December 2012 - 01:33 PM

Defining nullptr as size_t is not a good idea (will it work at all for assignments to pointer?)
Better use this: http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/nullptr#Solution_and_Sample_Code
const // It is a const object...
class nullptr_t
{
  public:
    template<class T>
    inline operator T*() const // convertible to any type of null non-member pointer...
    { return 0; }

    template<class C, class T>
    inline operator T C::*() const   // or any type of null member pointer...
    { return 0; }

  private:
    void operator&() const;  // Can't take address of nullptr

} nullptr = {};



#5006375 Feasibility of writing android apps purely through the NDK

Posted by Martins Mozeiko on 02 December 2012 - 02:24 PM

This is important because debugging with the NDK can only be done with sprintf()—you don’t have breakpoints or any stack-tracing abilities.

This is false. NDK comes with gdb and instructions how to use it (see docs/NDK-GDB.html).
I am using GDB to debug my NDK applications just fine. You can put breakpoints, singl-step, view and modify variable values, and everything else you can do with GDB.


#5003823 driver bug?

Posted by Martins Mozeiko on 24 November 2012 - 04:12 PM

if after calling
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
you did not get error with glGetError then it is a driver bug that it is not reporting error. Because you were binding 2D texture, but operating with cubemap texture.


#5003324 OpenGL for Linux and MacOSX?

Posted by Martins Mozeiko on 22 November 2012 - 03:36 PM

On MacOSX read this about how OpenGL development works there: http://www.geeks3d.com/20121109/overview-of-opengl-support-on-os-x/


#5001046 Marmalade: Angelscript runs fine on x86, crashes on ARM

Posted by Martins Mozeiko on 14 November 2012 - 06:24 PM

You can use C comments - /* ... */
I'm not sure about Marmelade, but GNU assembler also accepts # as delimiter for comments - the rest of line after # symbol will be viewed as comment


#5000073 Version of Visual Studio to use

Posted by Martins Mozeiko on 11 November 2012 - 07:11 PM

The first link is for updated VS2012 C++ compiler. It was released after VS2012. Read about it here: http://blogs.msdn.co...uture-of-c.aspx

The second link is for normal VS2012.


#4998740 Python 3.3.0 sort() method not working?

Posted by Martins Mozeiko on 07 November 2012 - 10:47 PM

That is happening because Python 3.x changed sort behavior. Now it can not sort elements with different types.
It kinda makes sense because what does it mean - to compare integer with string? Which is greater 1 or "1"? Try this yourself in Python - write print 1 < "1". Do you expect to see False ?


#4986041 Learning D3D; having issues creating shaders

Posted by Martins Mozeiko on 02 October 2012 - 06:45 AM

D3DX11CompileFromFile function has ppErrorMsgs argument that receives string with error message what went wrong. Use it.




PARTNERS