Tuesday, November 23, 2010

Force a compiler Failure

#define COMPILE_TIME_ASSERT(expr) \
typedef char compile_time_constraint[(expr)? 1:-1]

Wednesday, October 27, 2010

COMPARE

CMP Carry/Overflow

Private Virtual Functions

#include
using namespace std;

class A
{
virtual void print1() { cout "1 Aprivate" endl; }
public:
virtual void print2() { cout "2 Apublic" endl; }

class B : public A
{
virtual void print2() { cout << "2 Bprivate" endl; }
public:
virtual void print1() {cout << "1 Bpublic" endl; }

int main(int argv, char* argc[])
{
A a;
B b;
a.print2();
b.print1();
A* ab = &b;
ab->print2();
return 0;
}

outputs...

2 Apublic
1 Bpublic
2 Bprivate

Friday, August 6, 2010

Trigger Content

Sql Server:
SELECT TR.NAME, COM.*
FROM SYS.TRIGGERS TR, SYSCOMMENTS COM
WHERE TR.OBJECT_ID = COM.ID
AND TR.NAME='triggerhere'

Oracle:
SELECT *
FROM all_constraints
WHERE table_name='NAME_OF_YOUR_TABLE'
AND constraint_type='C';

Sunday, March 28, 2010

Synclock

"A SyncLock block behaves like a Try...Finally construction in which the Try block acquires an exclusive lock on lockobject and the Finally block releases it. Because of this, the SyncLock block guarantees release of the lock, no matter how you exit the block. This is true even in the case of an unhandled exception." - MSDN
Public Sub Foo()
Dim sText As String
Dim objLock As Object = New Object()
Try
Monitor.Enter(objLock)
Try
sText = "Hello"
Finally
Monitor.Exit(objLock)
End Try
Catch e As Exception
MessageBox.Show(e.Message)
End Try
End Sub
- DeveloperFusion

Friday, March 26, 2010

C: Compiling GNU Projects on Windows

I wanted to port the programs I commonly use on Linux to Windows. In particular I have been working on wdiff. A program that compares the differences word by word of two files.

Currently I have been able to successfully compile the program on windows through Cygwin. I also was able to reproduce it on my colleges Redhat server.

The steps I took were:

wget http://ftp.gnu.org/gnu/wdiff/
tar -xzvf wdiff-0.5.tar.gz
cd wdiff-0.5
./configre
make (install) wdiff

However, I would like to run the program natively on Windows similar to the Project: UnixUtils.

I am currently working on a custom port due to the fact that I cannot run ./configure to establish a make file. Suggestions would be greatly appreciated.

Sunday, January 31, 2010

Python vs Perl

EXTERIOR: DAGOBAH -- DAY
With Yoda strapped to his back, Luke climbs up one of
the many thick vines that grow in the swamp until he
reaches the Dagobah statistics lab. Panting heavily, he
continues his exercises -- grepping, installing new
packages, logging in as root, and writing replacements for
two-year-old shell scripts in Python.

YODA: Code! Yes. A programmer's strength flows from code
maintainability. But beware of Perl. Terse syntax... more
than one way to do it... default variables. The dark side
of code maintainability are they. Easily they flow, quick
to join you when code you write. If once you start down the
dark path, forever will it dominate your destiny, consume
you it will.

LUKE: Is Perl better than Python?

YODA: No... no... no. Quicker, easier, more seductive.

LUKE: But how will I know why Python is better than Perl?

YODA: You will know. When your code you try to read six months
from now.

Taken from: Python Humor

Thursday, January 21, 2010

Wednesday, November 18, 2009

C++ Inheritance

Implicit vs Explicit Calls in C++


(Base&)*this = rhs; // IMPLICIT CALL
(*this).Base::operator=(rhs); // EXPLICIT CALL

Tuesday, October 27, 2009

Categorical Syllogisms

I decided to review my Categorical Syllogisms. Since I am a Philosophy major I think its important to stay current in logic as its crucial in any philosophical discussion; perhaps I can go as far as saying logic is the fundamental of any worthwhile discussion. The next few posts will relate to Philosophy and Argumentative Logic.

Today I am reviewing Categorical Syllogism as there are only 5-7 rules of Syllogisms depending on your source. Some sources like to combine syllogistic rules.

A Categorical Syllogism is represented by three terms, a major term (P), a minor term (S) and a middle term (M). The major term is the predicate of the conclusion and the minor term is the subject of the conclusion. The predicate modifies the subject. Traditionally the major term is written first, followed by the minor term and a conclusion. It can be represented as such.

All M are p
All S are M
________
All S are P

To understand how premises are defined we must understand how they are distributed. I have borrowed the list of distributions from Wikipedia and added my own Venn diagrams for ease of learning.

  • In "All A are B"-propositions the subject (A) is distributed.
  • In "No A are B"-propositions both the subject (A) and the predicate (B) are distributed.
  • In "Some A are B"-propositions neither the subject nor the predicate are distributed.
  • In "Some A are not B"-propositions the predicate is distributed.
Distribution of Terms

Fallacy 1: Undistributed Middle
The middle term must be distributed at least once.
Fallacy 2: Illicit Major/Illicit Minor
If a term is distributed in the conclusion, then it must be distributed in a premise.
Fallacy 3: Exclusive Premises
If a term is distributed in the conclusion, then it must be distributed in a premise.
Fallacy 4: Drawing an affirmative conclusion from a negative premise, or drawing a negative conclusion from an affirmative premise.
A negative premise requires a negative conclusion, and a negative conclusion requires a negative premise. (Alternate rendering: Any syllogism having exactly one negative statement is invalid.)
Fallacy 5: Existential Fallacy
If both premises are universal, the conclusion cannot be particular.


Other useful resources:
Lander Edu
Csunx

Friday, March 6, 2009

Programmer Hierarchy

I was recently informed of the hierarchy of programmers chart. Its pretty amusing, however, I have disagree with placing Java at the bottom. As much as I dislike Java, it does have its place. In fact I would place it on par with C# or possibly above it. C# and Java have similar syntax and styling. Both rely on a virtual machine by CLR (common language runtime) and bytecode respectively. C#.Net programs tend to initialize faster than Java programs. However, C# has nowhere near the cross platform capabilities that Java actually does.

None the less, its an interesting read:



http://lukewelling.com/2006/08/03/java-programmers-are-the-erotic-furries-of-programming/

BCD and Binary Conversions

This article is to demonstrate a technique in converting from a standard unsigned integer and into a binary number. Although, this process is rarely complicated, there does rise the occasion where one does need an alternative method.

The current method usually relies on standard libraries or a simple mathematical process. Hexadecimal is converted easily to decimal by multiplying each digit by a power of 16 and adding the results.

However
, large numbers can easily surpass the registers that Intel has given us to with. This renders the provided multiplication and division built in functions unusable.

The first solution many get is to replicate multiplication and division by hand.
                   _25_
ie: 105 / 5 = 5 )105

10
5
This solution is carried out by placing integers into an array and treating the entire process as a series of subtraction. This process gets the jobs done but it negligent of space considering that each digit is represent by 8-bits. The number is therefore in BCD (Binary Coded Decimal).

A BCD is simply every digit converted into its binary equivalent and concatenated. However, the numbers do not actually represent the number in binary.

ie: 765 = 0x2FD = 0b1011111101 = BCDx0111 0110 0101

In this example the binary is two digits short than the BCD, but the advantages of binary can be seen as the numbers get larger. The problems compile trying to add or subtract BCD.

ie 765 = BCDx0111 0110 0101
+426 = BCDx0100 0010 0110
1191 = BCDx1011 1000 1011
11 9 11
6 6

1 0001 1001 0001
1 1 9 1
However, BCD can only represent up to decimal 9, therefore any number greater than five must be added by six. This creates an addition nightmare, and creates tremendous overhead with carrying additional bits. Imagine this process when carrying out division "by hand" method.

If BCD was converted into binary, this would be no problem.

765 = 0b1011111101
426 = 0b0110101010
1191=0b10010100111
The easiest method is a technique I found on hardware conversion from Hex to BCD. This articles technique solves the problem by easily converting the largest set of number to binary without relying on multiplication or division.

Shift and Add-3 Algorithm

  1. Shift the binary number left one bit.
  2. If 8 shifts have taken place, the BCD number is in the Hundreds, Tens, and Units column.
  3. If the binary value in any of the BCD columns is 5 or greater, add 3 to that value in that BCD column.
  4. Go to 1.


Demonstration on Hex to BCD: 0xE


Demonstration on Hex to BCD: 0xFF

The reverse is similar.
  1. Shift bit right.
  2. If bit is greater than 5, subtract three.
  3. Repeat.
The remaining problem is converting unsigned ints to compressed BCD. An unsigned int would be stored such as 6 = 0x0000 0000 0000 0110. The solution is to shift the bits into the unsigned int four bits at a time. Thus having a an array of compressed numbers within unsigned ints. Thus you can think of your array as looking at a long number in binary format through blinders. Think of 16bit real mode, it can only access 64k of memory at a time. Thus you would be accessing your array one "word" at a time.

References:

http://www.engr.udayton.edu/faculty/jloomis/ece314/notes/devices/binary_to_BCD/bin_to_BCD.html