Same functions with different return types in C++
Normally the following two functions would be considered the same:
int getdata ( char *s, int i )
long getdata ( char *s, int i )
Every other compiler we use would resolve both of these to the same function. In fact, it is not valid C++ code otherwise.
We include some 3rd party source in our build which sometimes messes with our typedefs causing this to happen. We have accounted for all of the function input types but never had a problem with the return types. I just installed Sun ONE Studio 8, Compiler Collection and it is generating two symbols in our libraries every time this occurs.
Is there a compiler flag I can use to stop it from doing this? I've got over 100 unresolved symbols and I'd rather not go and fix all of them if there is an easier way.
Normally the following two functions would be
considered the same:
int getdata ( char *s, int i )
long getdata ( char *s, int i )Not at all. Types int and long are different types, even if they are implemented the same way.
Reference: C++ Standard, section 3.9.1 paragraph 10.
For example, you can define two functions
void foo(int);
void foo(long);
and they are distinct functions. The function that gets called depends on function overload resolution at the point of the call.
Overloaded functions must differ in the number or the type of at least one parameter. They cannot differ only in the return type. A program that declares or defines two functions that differ only in their return types is invalid and has undefined behavior. Reference: C++ Standard section 13.1, paragraph 2.
The usual way to implement overloaded functions is to encode the scope and the parameter types, and maybe the return type, and attach the encoding to the function name. This technique is known as "name mangling". The compiler generates the same mangled name for the declaration and definition of a given function, and different mangled names for different functions. The linker matches up the mangled names, and can tell you when no definition matches a reference.
Some compilers choose not to include the return type in the mangled name of a function. In that case, the declaration
int foo(char*);
will match the definition
long foo(char*) { ... }
But it will also match the definitions
myClass foo(char*) { ... }
double foo(char*) { ... }
You are unlikely to get good results from such a mismatch. For that reason, and because a pointer-to-function must encode the function return type, Sun C++ always encodes the function return type in the mangled name. (That is, we simplify things by not using different encodings for the same function type.)
If you built your code for a 64-bit platform, it would presumably link using your other compilers, but would fail in mysterious ways at run time. With the Sun compiler, you can't get into that mess.
To make your program valid, you will have to ensure your function declarations match their definitions.
Similar Messages
-
Two methods with same name but different return type?
Can I have two methods with same name but different return type in Java? I used to do this in C++ (method overloading or function overloading)
Here is my code:
import java.io.*;
public class Test{
public static void main(String ar[]){
try{
//I give an invalid file name to throw IO error.
File file = new File("c:/invalid file name becasue of spaces");
FileWriter writer = new FileWriter(file ,true);
writer.write("Test");
writer.close();
} catch (IOException IOe){
System.out.println("Failure");
//call first method - displays stack trace on screen
showerr(NPe);
//call second method - returns stack trace as string
String msg = showerr(NPe);
System.out.println(msg);
} // end of main
public static void showerr(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
try{
pw.close();
sw.close();
catch (IOException IOe){
IOe.printStackTrace();
String stackTrace = sw.toString();
System.out.println("Null Ptr\n" + stackTrace );
}//end of first showerr
public static String showerr(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
try{
pw.close();
sw.close();
catch (IOException IOe){
IOe.printStackTrace();
return sw.toString();
}//end of second showerr
} // end of class
[\code]Overloading is when you have multiple methods that have the same name and the same return type but take different parameters. See example
public class Overloader {
public String buildError(Exception e){
java.util.Date now = new java.util.Date() ;
java.text.DateFormat format = java.text.DateFormat.getInstance() ;
StringBuffer buffer = new StringBuffer() ;
buffer.append(format.format(now))
.append( " : " )
.append( e.getClass().getName() )
.append( " : " )
.append( e.getMessage() ) ;
return buffer.toString() ;
public String buildError(String msg){
java.util.Date now = new java.util.Date() ;
java.text.DateFormat format = java.text.DateFormat.getInstance() ;
StringBuffer buffer = new StringBuffer() ;
buffer.append(format.format(now))
.append( " : " )
.append( msg ) ;
return buffer.toString() ;
public String buildErrors(int errCount){
java.util.Date now = new java.util.Date() ;
java.text.DateFormat format = java.text.DateFormat.getInstance() ;
StringBuffer buffer = new StringBuffer() ;
buffer.append(format.format(now))
.append( " : " )
.append( "There have been " )
.append( errCount )
.append( " errors encountered.") ;
return buffer.toString() ;
}Make sense ???
Regards, -
Interfaces having methods of same signature but different return types
I have two interfaces in two files:
public interface InterfaceA
int f();
public interface InterfaceB
void f();
Now I want to write a class that implements these two interfaces. Is it possible? If yes, could you please provide a code example?The easiest thing would be to change one of the names! Another approach is to have views of the class implement one or both interfaces.
Both:
class C {
private InterfaceA a = new InterfaceA() {
public int f() {
return 0;
public InterfaceA asA() {
return a;
private InterfaceB b = new InterfaceB() {
public void f() {
public InterfaceB asB() {
return b;
}One:
class B implements InterfaceB {
private InterfaceA a = new InterfaceA() {
public int f() {
return 0;
public InterfaceA asA() {
return a;
public void f() {
} -
Same Input name with different data type cause the reflection exception
I have a proxy contains couple RFCs. Two RFCs contain an argument named IN_COMPANY_CODE with data type of ZTRE_FX_BUKRSTable. Another RFC contains the same argument name of IN_COMPANY_CODE but hold different data type (String). All RFCs are in the same proxy. Complie and build the application with no issue.
But when I ran the RFC, it generates the reflection exception below:
Method SAPProxy1.Z_F_Tre_R_Pre_Trade_Fx can not be reflected. --> There was an error reflecting 'In_Company_Code'. > The XML element named 'IN_5fCOMPANY_--5fCODE' from namespace '' references distinct types System.String and MSTRFOREX.ZTRE_FX_BUKRSTable. Use XML attributes to specify another XML name or namespace for the element or types.
I realize the conflict introduced by the same name with difference data type. But I would like to know if this is fixable as a bug or if there is any best practice and/or some manual intervention to make it work.Please install fix from OSS note 506603. After this, right-click .sapwsdl file and select "Run custom tool".
-
Nesting of AGO or TODATE functions with differing level arguments is not supported
I have a column in BMM which calculates the Year-To-Date Sales. This function uses the ToDate function to caculate the YTD.
I need to develop another formula column which shows the last-year's YTD.
I develop this formula in BMM by AGO on the YTD column which already uses a ToDate function.
In BI Answers when selecting this column, results in the below message:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 22044] Nesting of AGO or TODATE functions with differing level arguments is not supported. (HY000)To reply to my own question. It appears I got it working, that is, the error message problem is solved, but I still have questions on how to use these functions.
To get it to work, I added the primary key D_TIJD.TIJDKEY at the level of the lowest grain in my dimension (level tab).
What I still wonder is how to make it select the right values. I have the following hierarchy: bookyear - bookperiod - week. A bookperiod contains 4 or 5 weeks (4,4,5 in a quarter), so 12 periods in one year. I defined a measure at period level and another at that level with the ago function, that should return the figures for that same period of the year before. My first question is, whether to go back 12 periods or 52 weeks (which is the lowest grain in my dimension)?
The second question is how to use a combination of TODATE and AGO so that if I calculate the current period (of which only 2 weeks are passed), I also only want to include the same two weeks for that period one year ago in order to make a correct comparison. How do I do that??? -
Merge of two same items with different Qty in po
Hi Experts,
Is it possible to merge two Same items with different Quantity into 1.
For Eg:- 2 similar items with qty 2 & 3 must show 5 qty appearing once.Is it possible through Transnotification what should be the query.
MonaHi Mona,
If you want to display a Purchase Order on screen summarized by item, set the "Summary Type" to "By Item" (by default it is "No Summary"). The PO lines will then be summarized by item with total quantity for each item.
If you want to display it on the printout then you need to modify the PLD. It is quite easy actually. You can use the Repetitive Area Footer to display the summary of each item and set all fields in the Repetitive Area to be not visible and set the height to minimum height.
Cheers,
Marini -
How to load and unload same SWF with different xmlFilePath?
I have a slideshow on my homepage and try to load and unload same instance with different xmlFilePath based on language on the same page.
var flashvars = {
xmlFilePath: escape("http://www.bodto.com.tr/kik.aspx"),
xmlFileType: "OPML",
lang: swfobject.getQueryParamValue("lang")
//initialURL: escape(document.location)
var params = {
bgcolor: "#000000",
allowfullscreen: "true",
wmode:"transparent",
allowScriptAccess: "always"
var attributes = {}
swfobject.embedSWF("/swf/slideshowpro.swf", "flashcontent", "550", "400", "10.0.0", false, flashvars, params, attributes);
Actionscript3
var langPath = root.LoaderInfo.parameters["xmlFilePath"]+root.LoaderInfo.parameters["lang"];
my_ssp.xmlFilePath = langPath;
var fileType = root.LoaderInfo.parameters["xmlFileType"];
my_ssp.xmlFileType = fileType;
Based on above informations, how could I achieve it?Suddenly that code in the following gives me some error
var langPath = root.LoaderInfo.parameters["xmlFilePath"]+root.LoaderInfo.parameters["lang"];
my_ssp.xmlFilePath = langPath;
var fileType = root.LoaderInfo.parameters["xmlFileType"];
my_ssp.xmlFileType = fileType;
Access of possibly undefined property LoaderInfo through a reference with static type flash.display:DisplayObject.
The only code snippet works is
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (var param in paramObj) {
if (param == "xmlFilePath") {
my_ssp.xmlFilePath = paramObj[param];
if (param == "xmlFileType") {
my_ssp.xmlFileType = paramObj[param]; -
Native method with String return type
Hi
i am implementing a Native method with String Return type.
i am able call the respective C++ method and my C++ method is printing the String (jstring in c++ code ) correctly
i but i am getting nullpointerexcepti while loading the string in to my Java String .
i am sure my java code calling the C++ code beacause my C++ code is printing the value and one more wonder is after the NPE my c++ code able to print the value
the code follows
HelloWorld.java
public class HelloWorld {
private native String print();
static {
System.loadLibrary("HelloWorld");
public static void main(String[] args) throws InterruptedException,NullPointerException{
HelloWorld hW= new HelloWorld();
for(int i=0;;i++){
String str= new HelloWorld().print();
System.out.println(str);
Thread.sleep(10000);
}and HelloWorld.cpp
// HelloWorld.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "jni.h"
#include <stdio.h>
#include "HelloWorld.h"
#include <windows.h>
#include "tchar.h"
#include "string.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
CHAR cpuusage(void);
typedef BOOL ( __stdcall * pfnGetSystemTimes)( LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime );
static pfnGetSystemTimes s_pfnGetSystemTimes = NULL;
static HMODULE s_hKernel = NULL;
void GetSystemTimesAddress()
if( s_hKernel == NULL )
s_hKernel = LoadLibrary(_T("Kernel32.dll"));
if( s_hKernel != NULL )
s_pfnGetSystemTimes = (pfnGetSystemTimes)GetProcAddress( s_hKernel, "GetSystemTimes" );
if( s_pfnGetSystemTimes == NULL )
FreeLibrary( s_hKernel ); s_hKernel = NULL;
// cpuusage(void)
// ==============
// Return a CHAR value in the range 0 - 100 representing actual CPU usage in percent.
CHAR cpuusage()
FILETIME ft_sys_idle;
FILETIME ft_sys_kernel;
FILETIME ft_sys_user;
ULARGE_INTEGER ul_sys_idle;
ULARGE_INTEGER ul_sys_kernel;
ULARGE_INTEGER ul_sys_user;
static ULARGE_INTEGER ul_sys_idle_old;
static ULARGE_INTEGER ul_sys_kernel_old;
static ULARGE_INTEGER ul_sys_user_old;
CHAR usage = 0;
// we cannot directly use GetSystemTimes on C language
/* add this line :: pfnGetSystemTimes */
s_pfnGetSystemTimes(&ft_sys_idle, /* System idle time */
&ft_sys_kernel, /* system kernel time */
&ft_sys_user); /* System user time */
CopyMemory(&ul_sys_idle , &ft_sys_idle , sizeof(FILETIME)); // Could been optimized away...
CopyMemory(&ul_sys_kernel, &ft_sys_kernel, sizeof(FILETIME)); // Could been optimized away...
CopyMemory(&ul_sys_user , &ft_sys_user , sizeof(FILETIME)); // Could been optimized away...
usage =
(ul_sys_kernel.QuadPart - ul_sys_kernel_old.QuadPart)+
(ul_sys_user.QuadPart - ul_sys_user_old.QuadPart)
(ul_sys_idle.QuadPart-ul_sys_idle_old.QuadPart)
(100)
(ul_sys_kernel.QuadPart - ul_sys_kernel_old.QuadPart)+
(ul_sys_user.QuadPart - ul_sys_user_old.QuadPart)
ul_sys_idle_old.QuadPart = ul_sys_idle.QuadPart;
ul_sys_user_old.QuadPart = ul_sys_user.QuadPart;
ul_sys_kernel_old.QuadPart = ul_sys_kernel.QuadPart;
return usage;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
return TRUE;
#ifdef _MANAGED
#pragma managed(pop)
#endif
JNIEXPORT jstring JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
int n;
GetSystemTimesAddress();
jstring s=(jstring)cpuusage();
printf("CPU Usage from C++: %3d%%\r",s);
return s;
}actually in the above code below part does that all, in the below code the printf statement printing correctly
JNIEXPORT jstring JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
int n;
GetSystemTimesAddress();
jstring s=(jstring)cpuusage();
printf("CPU Usage from C++: %3d%%\r",s);
return s;
}and the NPE i get is
Exception in thread "main" java.lang.NullPointerException
at HelloWorld.print(Native Method)
at HelloWorld.main(HelloWorld.java:10)
CPU Usage from C++: 6%any solution?
Thanks
R
Edited by: LoveOpensource on Apr 28, 2008 12:38 AMSee the function you wrote:
JNIEXPORT jstring JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)
int n;
GetSystemTimesAddress();
_jstring s=(jstring)cpuusage();_
printf("CPU Usage from C++: %3d%%\r",s);
return s;
}Here you try to cast from char to jstring, this is your problem, jstring Object should be created:
char str[20];
sprintf(str, "%3d", (int)cpuusage());
printf("CPU Usage from C++: %s%%\r",str);
jstring s=env->NewStringUTF(str);
return s; -
I have multiple album titles of the same name with different artists. How can I get them to go under one album title again?
In iTunes(on a Mac or PC) just tap on 'Albums' rather than 'Artists' and you'll see them all together.
You may find that there are songs mislabelled. In which case right tap on the Album or Artist and tap 'Get Info', then change to the correct name and the songs will join the rest of the songs for that Artist or Album.
Then resync with your iPhone and all will be well. -
How do I copy purchases between 2 itunes libraries on the same computer with different log ins and separate apple user ids?
Load the library which doesn't contain the songs and drag them into the open iTunes application window. If you need to move them between different computer user accounts, put them into /Users/Shared/.
(74502) -
Why can't two different users use Itunes on the same computer with different log ins
Why can't two different users use Itunes on the same computer with different log ins
Pmorgan5672 wrote:
Why can't two different users use Itunes on the same computer with different log ins
They can, but not at the same time.
If one user left iTunes running, and another user tries to use iTunes from a different Windows user ID, that second user will get an error message. If they really want to use iTunes, they either have to beg the first user to log in and close iTunes, or else they have to restart the computer.
If you are asking the technical reason why, it is something about context switching. -
CAn I run Lion and snow leopard on the same computer with different sign-ins?
CAn I run Lion and snow leopard on the same computer with different sign-ins?
Alternatively, partition your internal HD and dual-boot it. Do note that you have to reboot to switch back and forth. You can't do it by logging out and back in.
-
Can you have 2 ipods on the same accounts with different play list?
Can I have 2 ipods on the same accounts with different plalists?
Sure. Each iPod is identified in iTunes with its own name and you configure each one as you wish:
-
Posting of cross company transaction with different doc types
Hi,
The scenario is:-
We have two companies X and Y.
X makes a payment to Y with the following FI entries:-
Company Code X
Dr Vendor Y
Cr Bank HDFC
Company Code Y
Dr Bank ICICI
Cr Customer X
Now this needs to be a cross company transaction where the doc type for CC X should be vendor Payment 'KZ' while the doc type for CC Y should be a customer reciept with doc type 'DZ'.
Although I am able to map the accounts in cross company code config I am not able to split the transaction of different company codes with different document types.
Is there any way we can do this in standard SAP?
Thanks in advance,
NitishHi
As per your issue ...There are no possibilities to post in sap with different document types.
If you want you can post cross company code transactions with one document types
Regards
vamsi -
Same sqlID with different execution plan and Elapsed Time (s), Executions time
Hello All,
The AWR reports for two days with same sqlID with different execution plan and Elapsed Time (s), Executions time please help me to find out what is reason for this change.
Please find the below detail 17th day my process are very slow as compare to 18th
17th Oct 18th Oct
221,808,602
21
2tc2d3u52rppt
213,170,100
72,495,618
9c8wqzz7kyf37
209,239,059
71,477,888
9c8wqzz7kyf37
139,331,777
1
7b0kzmf0pfpzn
144,813,295
1
0cqc3bxxd1yqy
102,045,818
1
8vp1ap3af0ma5
128,892,787
16,673,829
84cqfur5na6fg
89,485,065
1
5kk8nd3uzkw13
127,467,250
16,642,939
1uz87xssm312g
67,520,695
8,058,820
a9n705a9gfb71
104,490,582
12,443,376
a9n705a9gfb71
62,627,205
1
ctwjy8cs6vng2
101,677,382
15,147,771
3p8q3q0scmr2k
57,965,892
268,353
akp7vwtyfmuas
98,000,414
1
0ybdwg85v9v6m
57,519,802
53
1kn9bv63xvjtc
87,293,909
1
5kk8nd3uzkw13
52,690,398
0
9btkg0axsk114
77,786,274
74
1kn9bv63xvjtc
34,767,882
1,003
bdgma0tn8ajz9
Not only queries are different but also the number of blocks read by top 10 queries are much higher on 17th than 18th.
The other big difference is the average read time on two days
Tablespace IO Stats
17th Oct
Tablespace
Reads
Av Reads/s
Av Rd(ms)
Av Blks/Rd
Writes
Av Writes/s
Buffer Waits
Av Buf Wt(ms)
INDUS_TRN_DATA01
947,766
59
4.24
4.86
185,084
11
2,887
6.42
UNDOTBS2
517,609
32
4.27
1.00
112,070
7
108
11.85
INDUS_MST_DATA01
288,994
18
8.63
8.38
52,541
3
23,490
7.45
INDUS_TRN_INDX01
223,581
14
11.50
2.03
59,882
4
533
4.26
TEMP
198,936
12
2.77
17.88
11,179
1
732
2.13
INDUS_LOG_DATA01
45,838
3
4.81
14.36
348
0
1
0.00
INDUS_TMP_DATA01
44,020
3
4.41
16.55
244
0
1,587
4.79
SYSAUX
19,373
1
19.81
1.05
14,489
1
0
0.00
INDUS_LOG_INDX01
17,559
1
4.75
1.96
2,837
0
2
0.00
SYSTEM
7,881
0
12.15
1.04
1,361
0
109
7.71
INDUS_TMP_INDX01
1,873
0
11.48
13.62
231
0
0
0.00
INDUS_MST_INDX01
256
0
13.09
1.04
194
0
2
10.00
UNDOTBS1
70
0
1.86
1.00
60
0
0
0.00
STG_DATA01
63
0
1.27
1.00
60
0
0
0.00
USERS
63
0
0.32
1.00
60
0
0
0.00
INDUS_LOB_DATA01
62
0
0.32
1.00
60
0
0
0.00
TS_AUDIT
62
0
0.48
1.00
60
0
0
0.00
18th Oct
Tablespace
Reads
Av Reads/s
Av Rd(ms)
Av Blks/Rd
Writes
Av Writes/s
Buffer Waits
Av Buf Wt(ms)
INDUS_TRN_DATA01
980,283
91
1.40
4.74The AWR reports for two days with same sqlID with different execution plan and Elapsed Time (s), Executions time please help me to find out what is reason for this change.
Please find the below detail 17th day my process are very slow as compare to 18th
You wrote with different execution plan, I think, you saw plans. It is very difficult, you get old plan.
I think Execution plans is not changed in different days, if you not added index or ...
What say ADDM report about this script?
As you know, It is normally, different Elapsed Time for same statement in different day.
It is depend your database workload.
It think you must use SQL Access and SQl Tuning advisor for this script.
You can get solution for slow running problem.
Regards
Mahir M. Quluzade
Maybe you are looking for
-
Trouble after installing ITunes 8.2 64bit
After upgrading/installing I cannot start ITunes. I get the message 'The ITunes library .itl file cannot be found or created. The default location for this file is in iTunes folder in the music folder.' I tried uninstalling iTunes then reinstalling b
-
G5 won't restart or shut down or change startup disc...
(after several updates) my computer won't restart or shut down except manually... which prevents me from changing the startup disc (where all my important stuff is). Option key during startup doesn't give me the startup disc option either. I'm stuck!
-
Switching from PC, what is this folder?
I am in the process of switching from a PC to my Macbook Pro so I'm not too familiar with the folders on the laptop. I have a folder on the root of the Macintosh HD called 775. It has nothing in it and I don't remember seeing it before. If I try to d
-
Definition of #HIGHLIGHT_ROW#
Hi, Is it correct that the parameter #HIGHLIGHT_ROW# in the report templates is containing the onmouseover and onmouseout event calls of a table row? If yes, is it possible to modify it? Thanks chrissy
-
HT1925 I can't install iTunes 11.1.4 on Windows Vista...
The message I keep getting is "MSVCR80.dll is not found. Re-installing will fix this problem." ....ater 4 attempts, it DIDN'T...HELP!!!!!!!