TORONTO -- The Toronto stock market snapped a three-session losing run to finish modestly higher Wednesday amid a mixed bag of earnings and a strong showing by gold miners.

The S&P/TSX composite index closed up 25.56 points to 11,492.51, with the main index held back by disappointing earnings from energy and base metal mining companies. The TSX Venture Exchange rose 5.86 points to 1,172.32.

However, analysts said no one should be surprised by the weak showing from resource companies.

"I think people should have expected that given commodity prices moving lower, and given some earlier announcements, that they shouldn't have expected good results out of there," said Sadiq Adatia, chief investment officer at Sun Life Global Investment.

A rapidly slowing Chinese economy would have provided a good indication of earnings growth, Adatia added.

The Canadian dollar was ahead 0.5 of a cent to 98.5 cents US.

U.S. markets were mixed.

The Dow Jones industrials ran ahead 58.73 points to 12,676.05, helped along by better-than-expected earnings reports from manufacturing giants Boeing and Caterpillar.

The Nasdaq composite index lost 8.75 points to 2,854.24 in the wake of an earnings disappointment from Apple Inc. after the close Tuesday while the S&P 500 index dipped 0.42 of a point to 1,337.89.

The gold sector led advancers, up about 2.8 per cent as bullion advanced $31.90 to US$1,608.10 an ounce. Barrick Gold Corp. (TSX:ABX) gained 73 cents to C$34.49. Barrick and Goldcorp Inc. (TSX:G) report quarterly earnings results Thursday.

The industrials sector also provided lift amid earnings from the country's two big railways.

CN Rail (TSX:CNR) reported adjusted earnings per share came in at $1.50, beating analyst estimates by two cents. But chief executive Claude Mongeau acknowledged that there could be an economic slowdown in the United States in the second half of this year and said he's also keeping an eye on China's economy. Despite the positive report, CN shares slipped 48 cents to $86.83.

Canadian Pacific Railway Ltd. (TSX:CP) said adjusted earnings were 90 cents per share, beating analyst expectations by seven cents and its shares climbed $3.91 or 5.2 per cent to $78.97.

The energy sector was ahead 0.13 per cent as the September crude contract on the New York Mercantile Exchange rose 47 cents to US$88.97 a barrel.

But Cenovus (TSX:CVE) shares fell 95 cents to C$31.15 as its profits dropped 40 per cent in the second quarter to $396 million as it faced weaker oil and gas prices.

The metals and mining sector led TSX losses, down 1.77 per cent while copper prices closed up two cents to US$3.37 a pound.

Teck Resources (TSX:TCK.B) slid $2.14 or 7.28 per cent to C$27.27 as it reported an adjusted profit of $312 million, or 53 cents per share, in the second quarter compared with $663 million, or $1.12 per share, in the same period in 2011. The slide came amid a weakening of base metal prices during the quarter. Quarterly revenues were $2.6 billion, compared with $2.8 billion a year ago.

Teck also warned of tough times ahead due to economic uncertainties in Europe and the United States and less robust growth rates in emerging markets including China.

The consumer staples sector was also weak, reflecting lower earnings at grocer Loblaw Cos. Ltd. (TSX:L).

The company reported quarterly net earnings of $159 million or 56 cents a share,down almost 19 per cent compared to the same period in 2011 and missing estimates by five cents and its shares lost 47 cents to $31.45.

In the U.S., Apple shares were down 4.3 per cent to US$574.97 after the company reported its slowest growth in more than two years. Quarterly net income was $8.8 billion, or $9.32 per share, up 21 per cent from a year ago. Analysts expected earnings of $10.37 per share. Revenue was $35 billion, lower than expectations for $37.5 billion.

Caterpillar shares rose 1.44 per cent to US$82.60 after posting net income of US$1.7 billion, or $2.54 a share, up from $1.02 billion, or $1.52, a year earlier. The world's largest maker of construction and mining equipment beat expectations by 24 cents. Caterpillar also raised its full year earnings forecast.

Aircraft maker Boeing topped analyst estimates, turning in net income of US$967 million or $1.27 a share, higher than the $1.13 that had been forecast. Boeing also boosted its full-year outlook and its shares rose 2.78 per cent to US$74.03.

The eurozone debt crisis has cast a shadow over markets this week on elevated concerns that Spain, Europe's fourth-biggest economy, will need a bailout as the country is forced to pay ever higher amounts to fund its debt. Yields on the country's key 10-year Treasuries have remained above the sever per cent level, which is considered unsustainable.

There was some good news on that front Wednesday as the yield on the Spain's 10-year government bond fell to 7.37 per cent from 7.53 per cent late Tuesday. That's a positive sign that investors are slightly less worried about Spain's ability to repay its debts.

Markets had faltered mid-morning after the U.S. Commerce Department said sales of new homes plunged eight per cent last month to an annual rate of 350,000, much lower than the 373,000 pace that economists expected. It was the slowest pace in five months and the steep decline suggested a weaker job market could make the housing recovery slow and uneven.