DAKAR, Senegal (CNN) -- U.S. President Barack Obama on Thursday called on countries throughout the world to decriminalize homosexuality, a day after the U.S. Supreme Court handed a major victory to proponents of same-sex marriage.
Every group of people has a right to its own views, Obama said, and that diversity should be respected, "but when it comes to how the state treats people -- how the law treats people -- I believe that everybody has to be treated equal." He spoke at a news conference with President Macky Sall of Senegal, a country in which homosexuality is illegal.
"Regardless of race, regardless of religion, regardless of gender, regardless of sexual orientation ... people should be treated equally, and that's a principle that I think applies universally," Obama said.
The remarks came in response to a question from CNN as to whether he was pressing Sall on the issue.
Obama said the issue did not come up in their talks, but that the question of how gays and lesbians are treated has been coming up in Africa in general.
Sall responded that his country has no plans to decriminalize homosexuality.
"Senegal is a very tolerant country which does not discriminate in terms of inalienable rights of human beings," he said, according to an official translation. People are not refused jobs for being gay, he said. "But we are still not ready to decriminalize homosexuality."
"But of course this does not mean that we are all homophobic," Sall insisted.
Sall then turned to another issue on which the two nations differ: capital punishment.
"In our country we have abolished it for many years," he said, adding, "We do respect the choice of each country."
Obama left the United States on Wednesday for a trip to Senegal, South Africa, and Tanzania -- his second visit to sub-Saharan Africa since taking office.
The trip aims to bolster investment opportunities for U.S. businesses, address development issues such as food security and health, and promote democracy. It comes as China aggressively engages the continent. The Asian nation is pouring billions of dollars into Africa, running oil and mining firms, and in 2009 replaced the United States as the largest trading partner.
At Thursday's news conference, Obama was asked to assess the big news at home -- the Supreme Court ruling Wednesday striking down a key part of the Defense of Marriage Act.
The decision was "not simply a victory for the LGBT community," he said, referring to lesbian, gay, bisexual and transgender people. "I think it was a victory for American democracy."
"I believe at the root of who we are as a people, as Americans, is the basic precept that we are all equal under the law. We believe in basic fairness. And what I think yesterday's ruling signifies is one more step towards ensuring that those basic principles apply to everybody," Obama said in response to a question from CNN's Jessica Yellin.
His administration will now have to comb through every federal statute, he said, to ensure that federal benefits "apply to all married couples."
There are complexities, he noted. Since some states recognize same-sex marriages and others don't, the government will need to determine whether a same-sex couple remains married under federal law after moving to a state that does not recognize the marriage.
Obama also spoke of ailing former South African President Nelson Mandela, who is in critical condition in a Pretoria hospital.
"My first act of political activism was when I was at Occidental College as a 19-year-old -- I got involved in the anti-apartheid movement," Obama said.
He said he was inspired by what was taking place at the time in South Africa. He had read Mandela's writings and speeches, and understood "that this was somebody who believed in that basic principle I just talked about -- treating people equally -- and was willing to sacrifice his life for that belief."
Mandela "is a personal hero" and "a hero for the world," Obama said. "And if and when he passes from this place, one thing I think we'll all know is that his legacy is one that will linger on throughout the ages."
Obama's visit to South Africa on Saturday will include a visit to Robben Island, where Mandela spent a majority of his 27 years in prison. The White House schedule does not include a visit with the anti-apartheid icon.
CNN's Faith Karimi contributed to this report.