If C is the defender, and A and B are both at war with C, then both A and B will join in the battle as attackers against C.
This will not work if C is the attacker. In that case, either A or B will be the defender, C will attack, and the odd man out will grab the beer and pizza, and watch the battle from the sidelines.
If C is running a TO, then it is safe to assume they will be the defender. In any other situation, there is probably at least a small chance that some quirk of the system will cause C to be the attacker. This is why it's important to have clear and obvious diplomacy. If you want to help someone, you should ally with them.