Saturday, March 22, 2008

Math Object Wrap Space in's Writer

(Mar 22, 2008)

By default, math object wrap space in OO.o's Writer is pretty annoying. If a math object is at the end of a sentence and follows by a foot stop, the foot stop will be put too far from the math object. Earlier, I needed to put it inside the problematic math object. Although the printing output was fine, it changed semantics of the math object.

OO.o, however, has a solution for this. In case we want to change a specific wrap space for a specific math object, we can right click on the math object, go to 'Option', then 'Wrap', and set 'Spacing' to zero as shown in figures below.

In case we want to set zero space as a default setting, we can use 'Styles and Formatting'. Formula setting can be accessed from 'Frame Styles' as shown below.


Wednesday, March 19, 2008

Importance of WINVER definition in Visual Studio 2008

(Mar 19, 2008)

Recently, MIPL starts to port stuff to VS 2008. It turns out that code compiled on Vista worked 100% correct only on Vista, but on Windows XP, it showed some glitches.

This is because the default WINVER in VS 2008 is 0x0600 (Vista). Thus, when we build our code, it will perform some Vista specific links, and an executable file may not work correctly on XP.

To solve this problem, just go to StdAfx.h and put the definition of WINVER to XP:

#define WINVER 0x0501

With this definition, built executable files should work on both XP and Vista.

Tuesday, March 18, 2008

เรื่องงงๆ ใน OpenOffice

(Mar 18, 2008)

พยายามใช้ Style and Formatting ใน OpenOffice แล้วปรากฎว่าเวลาเปลี่ยนไสตล์แล้วรูปแบบตัวอักษรมันไม่ได้เปลี่ยนไปด้วยเลย ทั้งที่แต่ก่อนมันก็เปลี่ยนให้เราเอง พยายามยังไงมันก็ยังไม่ยอมเปลี่ยนให้แบบอัตโนมัติเหมือนเคย

แต่ยังไงเราก็พบว่าถ้าเราไฮไลต์มันแล้วคลิกขวา จากนั้นก็เลือก Default formatting มันก็จะจัดรูปแบบให้เราตามที่เรากำหนดไว้ ถ้าไม่อยากใช้เมาส์ จะกด Ctrl+Shft+Space ก็ได้

Alias can be a tricky problem in C++'s STL vector

(Mar 14, 2008)

Alias can be a tricky problem in C++'s STL vector.

Sometimes, I don't want to write an awkward code such as willFail.m_vecProblematic[0] all the time, so I create an alias (prob1 in this example). This alias will work fine until we push or pop elements in a vector to a certain number and the vector is needed to reallocate.

Problematic* prob1 = &( willFail.m_vecProblematic[0] );
prob1->m_vec2.push_back( 55 );
prob1->m_vec1.push_back( 11111 );

// Push an element to a vector may cause a vector to reallocate.
willFail.m_vecProblematic.push_back( Problematic );

// prob1 may not point to a correct storage, but this value assignment

// may not cause a program to crash instantly.
prob1->i = 24;

// prob1 may not point to a correct storage, and such object

// operation usually cause a program to crash
prob1->m_vec2.push_back( 66 );

Note: simple value assignment to an invalid place may not cause a program to crash so easily, but calling a method from an invalid object pointer will cause a program to crash very easily since the method table of an object is already messed up. If we want to find where a program goes wrong, we may try to call a method of a suspecious object pointer.