It's kind of a long article, but this is an excerpt
Reefs are large underwater structures of coral skeletons, made from calcium carbonate secreted by generation after generation of tiny coral polyps over sometimes millions of years of coral growth in the same location. The team showed that corals can switch from using aragonite to another mineral, calcite, in making the calcium carbonate. They make that switch in response to decreases in the ratio of magnesium to calcium in seawater, Ries said. That ratio has changed dramatically over geologic time.
Though most scientists believed that corals were programmed to produce only the aragonitic form of calcium carbonate, he said, the team's work reveals that corals are far more flexible and able to vary at least a portion of their skeleton to growth favored by seawater chemistry. He postulates that this "mineralogical flexibility" provides corals with an "evolutionary advantage," as it would take more energy for corals to produce skeletons that are not favored by the chemistry of the seawater surrounding them