在編寫程序時,我遇到了一些問題,因爲我正在編寫一些代碼來進行調試。我在程序中有很多鏈接,我相信其中一個問題出現在鏈接中,所以我試圖編寫一個程序來輸出未能鏈接的變量的名稱。我的努力失敗了,來到這裏尋求幫助。這裏是我的代碼:如何輸出輸入變量的名稱
GstElement element1, element2; //this is debugging a gstreamer program
void testforfailure(element1, element2)
{
if(!gst_element_link(element1, element2))
{
printf("linkage of");
printf(element1); //I want this to be the name of the element calling the function
printf(" and ");
printf(element2);
printf(" failed.");
return -1;
}
}
調用示例:
GstElement *source, *sink;
testforfailure(source, sink); //if link(source, sink) fails, then this should output "linkage of source and sink failed"
如果有人可以幫助我解決這個問題,那將是巨大的。
編輯:看到這是不可能的,我設計了一個簡單的解決方案:
testsignalforfailure(GstElement *elem1, GstElement *elem2, int id, int id2)
{
if(!gst_element_link(elem1, elem2))
{
g_print("linkage of %d and %d failed", id, id2);
return -1;
}
}
當所謂的 「testsignalforfailure(源,水槽,1,2)」,這給我的唯一的ID(自定義)未能鏈接的元素(我在運行之前向每個元素聲明瞭一個id)。感謝大家的幫助。
變量在傳遞給函數之前的名稱?那是不可能的...... – GBa
你是什麼意思的「鏈接」? – pmg
老實說,**很難說出這裏要問什麼。這個問題含糊不清,含糊不清,不完整,過於寬泛,或修辭,並且不能以其目前的形式合理地回答。** –