Which build to be considered for use when a preprocessor is used

帅比萌擦擦* 提交于 2019-12-13 04:40:51

问题


I have a project which needs to be used in 4.6 and 5.0 versions of blackberry. I have run same code in both the 4.6 and 5.0 versions with some preprocessor directives attached to the code (#ifndef statements which i need to use for 5.0 as facebook sdk is not supported in 4.6 version) I have 2 .cod files ( one for 4.6 and other for 5.0) they work as needed in their respective simulators.

But, when i load the .cod file of 4.6 into 5.0 ... (it treats it as the code inside preprocessor as comment) and when i do it viceversa

ie from 5.0 into 4.6 ... it says ... projectname-1.cod not found .

A similar question is been posted here too check out where a comment on bbtool says it can be possible One build for two different versions (4.6,4.7 and 5.0+above) in blackberry


回答1:


Using preprocessor is not the way to make A SINGLE BUILD for different BB OS Versions (No matter what tool you use to prepare the build).

Preprocessors are used just to remove/add particular portion of code based on provided conditions before compiling/building the entire code. More generally, preprocessors are used to consider the source code differently for different conditions. More more generally, preprocessors are used to produce different source codes for different conditions. In such a case the scope of preprocessors is only before compiling/building the code... not after you have build the code and got the executable/.cod/...etc. file

Read first few lines of T H E S E links; though these are about C-Preprocessors, but the basic is also applicable here.

Suppose your code is as following:

// START OF CODE
//#preprocess
// this is the second line of the code
//...
//#ifdef OS_5
import net.rim.device.api.ui.component.AutoCompleteField;
//#else
//don't import AutoCompleteField and import something else if needed
//#endif

//...
//... // some more codes
//...

//#ifdef OS_5
//...
//...
// Codes for using AutoCompleteField
//...
//...
//#else
//...
//...
// Codes for implementing AutoCompleteField another way by yourself
//...
//...

//...
//... // some more codes
//...
 // END OF CODE

It doesn't matter what tool you use to build your code (JDE, Eclipse or using Ant), if you build with the preprocessor 'OS_5' then (if your tool can understand preprocessors) the following code will be generated :

// START OF CODE
// this is the second line of the code
//...
import net.rim.device.api.ui.component.AutoCompleteField;

//...
//... // some more codes
//...

//...
//...
// Codes for using AutoCompleteField
//...
//...

//...
//... // some more codes
//...
 // END OF CODE

and the .cod file will be generated with the above code. And this .cod file will not run on BB OS Versions less than 5.0 because AutoCompleteField is supported from OS 5.

And if you build without the preprocessor 'OS_5' or other preprocessors then the following code will be generated:

// START OF CODE
// this is the second line of the code
//...
//don't import AutoCompleteField and import something else if needed

//...
//... // some more codes
//...


//...
//...
// Codes for implementing AutoCompleteField another way by yourself
//...
//...

//...
//... // some more codes
//...
 // END OF CODE

and the .cod file will be generated using the above code, and This is going to be a different .cod file than the previous one.

Now if you want to prepare A SINGLE BUILD and deploy it successfully different BB OS supported devices, then you have to remove dependencies while coding, i.e. use only those API-classes that are supported by all the OS versions (4.6, 5.0... and others if you want). But it's very difficult sometimes for some cases, because you may have to write your own codes for implementing some features.

It's easier to prepare different builds for different OS --- and on that purpose you can of course use preprocessors..


I'm afraid may be I have explained an easy thing in a very complex way.



来源:https://stackoverflow.com/questions/10445072/which-build-to-be-considered-for-use-when-a-preprocessor-is-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!