Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8711 > unrolled thread

preprocessor idea

Started byPhilipp Kraus <philipp.kraus@flashpixx.de>
First post2011-10-11 20:19 +0200
Last post2011-10-12 07:04 -0700
Articles 11 — 5 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  preprocessor idea Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-10-11 20:19 +0200
    Re: preprocessor idea Robert Klemme <shortcutter@googlemail.com> - 2011-10-11 21:57 +0200
      Re: preprocessor idea markspace <-@.> - 2011-10-11 13:14 -0700
    Re: preprocessor idea Arne Vajhøj <arne@vajhoej.dk> - 2011-10-11 19:17 -0400
      Re: preprocessor idea Robert Klemme <shortcutter@googlemail.com> - 2011-10-13 18:35 +0200
        Re: preprocessor idea Arne Vajhøj <arne@vajhoej.dk> - 2011-10-13 22:49 -0400
          Re: preprocessor idea Robert Klemme <shortcutter@googlemail.com> - 2011-10-16 23:56 +0200
            Re: preprocessor idea Arne Vajhøj <arne@vajhoej.dk> - 2011-10-16 22:32 -0400
              Re: preprocessor idea Robert Klemme <shortcutter@googlemail.com> - 2011-10-17 18:53 +0200
                Re: preprocessor idea Arne Vajhøj <arne@vajhoej.dk> - 2011-11-06 17:03 -0500
    Re: preprocessor idea Roedy Green <see_website@mindprod.com.invalid> - 2011-10-12 07:04 -0700

#8711 — preprocessor idea

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-10-11 20:19 +0200
Subjectpreprocessor idea
Message-ID<j721b6$dam$1@online.de>
Hello,

I use within my Java code different external libraries (DLL), so I have 
create a string array with their names
so the libraries can be load with System.load / System.loadLibrary.

I build the libraries (C++ code) with a toolchain and I use a lot of 
preprocessor commands within
the C++ code, so I can enable or disable some function and so the using 
of the libraries eg:

c++:
#ifdef lib1
#endif

#ifdef lib2
#endif

So my Java code must load lib1 and lib2 if both defs are set. Java does 
not support any preprocessor
flags, but in this case I need a tip for creating a flexiable Java code 
during the class is compiled
(eg: ifdef1 = true => String[] javaarray = {"lib1"}). Do you know any 
idea for this problem?

Thanks

Phil

[toc] | [next] | [standalone]


#8714

FromRobert Klemme <shortcutter@googlemail.com>
Date2011-10-11 21:57 +0200
Message-ID<9fjlcpFdmU1@mid.individual.net>
In reply to#8711
On 10/11/2011 08:19 PM, Philipp Kraus wrote:

> I use within my Java code different external libraries (DLL), so I have
> create a string array with their names
> so the libraries can be load with System.load / System.loadLibrary.

That's the wrong approach IMHO: make the interface classes load the DDL 
they need at class load time (e.g. in a static initializer block).  This 
best fits the Java model of dynamically deciding what code to use.

> I build the libraries (C++ code) with a toolchain and I use a lot of
> preprocessor commands within
> the C++ code, so I can enable or disable some function and so the using
> of the libraries eg: >
> Thanks
>
> Phil
>


Why do you want to decide this in C++ land?

> c++:
> #ifdef lib1
> #endif
>
> #ifdef lib2
> #endif
>
> So my Java code must load lib1 and lib2 if both defs are set. Java does
> not support any preprocessor
> flags, but in this case I need a tip for creating a flexiable Java code
> during the class is compiled
> (eg: ifdef1 = true => String[] javaarray = {"lib1"}). Do you know any
> idea for this problem?

Again, IMHO this is the wrong approach: you should create your libraries 
with all the functionality you need and only determine via Java classes 
which are used or not used what DLLs are loaded and used.

If you really want to make the decision in C++ land you could use your 
preprocessor to have different variants of a JNI method which returns 
information which lets you determine in Java which DLL's to load.  You 
could have a native method which returns a String[] with DLL names etc.

Kind regards

	robert

[toc] | [prev] | [next] | [standalone]


#8718

Frommarkspace <-@.>
Date2011-10-11 13:14 -0700
Message-ID<j7282d$vgc$1@dont-email.me>
In reply to#8714
On 10/11/2011 12:57 PM, Robert Klemme wrote:
> a JNI method which returns
> information which lets you determine in Java which DLL's to load. You
> could have a native method which returns a String[] with DLL names etc.


+1.  I could cite some design patterns or whatnot why this is probably 
the best approach but "common sense" is I think the most applicable 
design pattern here.  Why go around your elbow to get from your 
forefinger to your thumb?

[toc] | [prev] | [next] | [standalone]


#8724

FromArne Vajhøj <arne@vajhoej.dk>
Date2011-10-11 19:17 -0400
Message-ID<4e94ce75$0$284$14726298@news.sunsite.dk>
In reply to#8711
On 10/11/2011 2:19 PM, Philipp Kraus wrote:
> I use within my Java code different external libraries (DLL), so I have
> create a string array with their names
> so the libraries can be load with System.load / System.loadLibrary.
>
> I build the libraries (C++ code) with a toolchain and I use a lot of
> preprocessor commands within
> the C++ code, so I can enable or disable some function and so the using
> of the libraries eg:
>
> c++:
> #ifdef lib1
> #endif
>
> #ifdef lib2
> #endif
>
> So my Java code must load lib1 and lib2 if both defs are set. Java does
> not support any preprocessor
> flags, but in this case I need a tip for creating a flexiable Java code
> during the class is compiled
> (eg: ifdef1 = true => String[] javaarray = {"lib1"}). Do you know any
> idea for this problem?

Run the Java code through the C preprocessor with the same defines.

String[] javaarray = {
"None"
#ifdef lib1
,"lib1"
#endif
#ifdef lib1
,"lib1"
#endif
};

Arne

[toc] | [prev] | [next] | [standalone]


#8763

FromRobert Klemme <shortcutter@googlemail.com>
Date2011-10-13 18:35 +0200
Message-ID<9foia2FjbkU1@mid.individual.net>
In reply to#8724
On 12.10.2011 01:17, Arne Vajhøj wrote:
> On 10/11/2011 2:19 PM, Philipp Kraus wrote:
>> I use within my Java code different external libraries (DLL), so I have
>> create a string array with their names
>> so the libraries can be load with System.load / System.loadLibrary.
>>
>> I build the libraries (C++ code) with a toolchain and I use a lot of
>> preprocessor commands within
>> the C++ code, so I can enable or disable some function and so the using
>> of the libraries eg:
>>
>> c++:
>> #ifdef lib1
>> #endif
>>
>> #ifdef lib2
>> #endif
>>
>> So my Java code must load lib1 and lib2 if both defs are set. Java does
>> not support any preprocessor
>> flags, but in this case I need a tip for creating a flexiable Java code
>> during the class is compiled
>> (eg: ifdef1 = true => String[] javaarray = {"lib1"}). Do you know any
>> idea for this problem?
>
> Run the Java code through the C preprocessor with the same defines.
>
> String[] javaarray = {
> "None"
> #ifdef lib1
> ,"lib1"
> #endif
> #ifdef lib1
> ,"lib1"
> #endif
> };

I do not think it's worthwhile to open that can of worms for this 
decision.  After all getting rid of the CPP is one of the major 
advantages of Java over C++ (even Stroustrup regrets not having ripped 
it out of C++) and complicating the Java build process just for that 
decision seems too heavy - especially since there are other solutions 
available.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [next] | [standalone]


#8776

FromArne Vajhøj <arne@vajhoej.dk>
Date2011-10-13 22:49 -0400
Message-ID<4e97a33b$0$282$14726298@news.sunsite.dk>
In reply to#8763
On 10/13/2011 12:35 PM, Robert Klemme wrote:
> On 12.10.2011 01:17, Arne Vajhøj wrote:
>> On 10/11/2011 2:19 PM, Philipp Kraus wrote:
>>> I use within my Java code different external libraries (DLL), so I have
>>> create a string array with their names
>>> so the libraries can be load with System.load / System.loadLibrary.
>>>
>>> I build the libraries (C++ code) with a toolchain and I use a lot of
>>> preprocessor commands within
>>> the C++ code, so I can enable or disable some function and so the using
>>> of the libraries eg:
>>>
>>> c++:
>>> #ifdef lib1
>>> #endif
>>>
>>> #ifdef lib2
>>> #endif
>>>
>>> So my Java code must load lib1 and lib2 if both defs are set. Java does
>>> not support any preprocessor
>>> flags, but in this case I need a tip for creating a flexiable Java code
>>> during the class is compiled
>>> (eg: ifdef1 = true => String[] javaarray = {"lib1"}). Do you know any
>>> idea for this problem?
>>
>> Run the Java code through the C preprocessor with the same defines.
>>
>> String[] javaarray = {
>> "None"
>> #ifdef lib1
>> ,"lib1"
>> #endif
>> #ifdef lib1
>> ,"lib1"
>> #endif
>> };
>
> I do not think it's worthwhile to open that can of worms for this
> decision. After all getting rid of the CPP is one of the major
> advantages of Java over C++ (even Stroustrup regrets not having ripped
> it out of C++) and complicating the Java build process just for that
> decision seems too heavy - especially since there are other solutions
> available.

What other solution achieve the same?

Arne

[toc] | [prev] | [next] | [standalone]


#8872

FromRobert Klemme <shortcutter@googlemail.com>
Date2011-10-16 23:56 +0200
Message-ID<9g127uF848U1@mid.individual.net>
In reply to#8776
On 10/14/2011 04:49 AM, Arne Vajhøj wrote:
> On 10/13/2011 12:35 PM, Robert Klemme wrote:
>> On 12.10.2011 01:17, Arne Vajhøj wrote:

>>> Run the Java code through the C preprocessor with the same defines.
>>>
>>> String[] javaarray = {
>>> "None"
>>> #ifdef lib1
>>> ,"lib1"
>>> #endif
>>> #ifdef lib1
>>> ,"lib1"
>>> #endif
>>> };
>>
>> I do not think it's worthwhile to open that can of worms for this
>> decision. After all getting rid of the CPP is one of the major
>> advantages of Java over C++ (even Stroustrup regrets not having ripped
>> it out of C++) and complicating the Java build process just for that
>> decision seems too heavy - especially since there are other solutions
>> available.
>
> What other solution achieve the same?

Please see elsewhere in this thread.

Kind regards

	robert

[toc] | [prev] | [next] | [standalone]


#8895

FromArne Vajhøj <arne@vajhoej.dk>
Date2011-10-16 22:32 -0400
Message-ID<4e9b93ce$0$284$14726298@news.sunsite.dk>
In reply to#8872
On 10/16/2011 5:56 PM, Robert Klemme wrote:
> On 10/14/2011 04:49 AM, Arne Vajhøj wrote:
>> On 10/13/2011 12:35 PM, Robert Klemme wrote:
>>> On 12.10.2011 01:17, Arne Vajhøj wrote:
>
>>>> Run the Java code through the C preprocessor with the same defines.
>>>>
>>>> String[] javaarray = {
>>>> "None"
>>>> #ifdef lib1
>>>> ,"lib1"
>>>> #endif
>>>> #ifdef lib1
>>>> ,"lib1"
>>>> #endif
>>>> };
>>>
>>> I do not think it's worthwhile to open that can of worms for this
>>> decision. After all getting rid of the CPP is one of the major
>>> advantages of Java over C++ (even Stroustrup regrets not having ripped
>>> it out of C++) and complicating the Java build process just for that
>>> decision seems too heavy - especially since there are other solutions
>>> available.
>>
>> What other solution achieve the same?
>
> Please see elsewhere in this thread.

Well - they do not seem to be on my news server.

The only suggestion it carry are yours of:
* changing the logic, which may be a good idea, but is definitely
   not the same
* use JNI to get the info from the native side, which will
   require approx. 10 as much code than this

Arne

[toc] | [prev] | [next] | [standalone]


#8924

FromRobert Klemme <shortcutter@googlemail.com>
Date2011-10-17 18:53 +0200
Message-ID<9g34seFjqlU1@mid.individual.net>
In reply to#8895
On 10/17/2011 04:32 AM, Arne Vajhøj wrote:
> On 10/16/2011 5:56 PM, Robert Klemme wrote:
>> On 10/14/2011 04:49 AM, Arne Vajhøj wrote:
>>> On 10/13/2011 12:35 PM, Robert Klemme wrote:
>>>> On 12.10.2011 01:17, Arne Vajhøj wrote:
>>
>>>>> Run the Java code through the C preprocessor with the same defines.
>>>>>
>>>>> String[] javaarray = {
>>>>> "None"
>>>>> #ifdef lib1
>>>>> ,"lib1"
>>>>> #endif
>>>>> #ifdef lib1
>>>>> ,"lib1"
>>>>> #endif
>>>>> };
>>>>
>>>> I do not think it's worthwhile to open that can of worms for this
>>>> decision. After all getting rid of the CPP is one of the major
>>>> advantages of Java over C++ (even Stroustrup regrets not having ripped
>>>> it out of C++) and complicating the Java build process just for that
>>>> decision seems too heavy - especially since there are other solutions
>>>> available.
>>>
>>> What other solution achieve the same?
>>
>> Please see elsewhere in this thread.
>
> Well - they do not seem to be on my news server.
>
> The only suggestion it carry are yours of:
> * changing the logic, which may be a good idea, but is definitely
> not the same

Do you say that because of

> Java does not support any preprocessor
> flags, but in this case I need a tip for creating a flexiable Java code during the class is compiled
> (eg: ifdef1 = true => String[] javaarray = {"lib1"})

?  Right, I took the liberty to ignore the specific requirement to 
change the Java code because I consider the ultimate task to solve to 
only load those libs which can be used.  Changing the Java code is just 
one means to that end.

> * use JNI to get the info from the native side, which will
> require approx. 10 as much code than this

Well, but the solution to use CPP for Java code will probably need a 
similar amount of code - even if it's not in Java but in ant scripts or 
Makefiles.  And it will be a dramatic change to the build process.  One 
also needs to decide whether to apply CPP to all Java files or just 
selectively to a single one.  The first option is probably cleaner from 
a build process point of view but increases the risk of bugs (i.e. if 
CPP starts replacing things in other files that it is not supposed to 
change) while the second solution is an ugly crutch IMHO.

Kind regards

	robert

[toc] | [prev] | [next] | [standalone]


#9684

FromArne Vajhøj <arne@vajhoej.dk>
Date2011-11-06 17:03 -0500
Message-ID<4eb70446$0$288$14726298@news.sunsite.dk>
In reply to#8924
On 10/17/2011 12:53 PM, Robert Klemme wrote:
> On 10/17/2011 04:32 AM, Arne Vajhøj wrote:
>> On 10/16/2011 5:56 PM, Robert Klemme wrote:
>>> On 10/14/2011 04:49 AM, Arne Vajhøj wrote:
>>>> On 10/13/2011 12:35 PM, Robert Klemme wrote:
>>>>> On 12.10.2011 01:17, Arne Vajhøj wrote:
>>>
>>>>>> Run the Java code through the C preprocessor with the same defines.
>>>>>>
>>>>>> String[] javaarray = {
>>>>>> "None"
>>>>>> #ifdef lib1
>>>>>> ,"lib1"
>>>>>> #endif
>>>>>> #ifdef lib1
>>>>>> ,"lib1"
>>>>>> #endif
>>>>>> };
>>>>>
>>>>> I do not think it's worthwhile to open that can of worms for this
>>>>> decision. After all getting rid of the CPP is one of the major
>>>>> advantages of Java over C++ (even Stroustrup regrets not having ripped
>>>>> it out of C++) and complicating the Java build process just for that
>>>>> decision seems too heavy - especially since there are other solutions
>>>>> available.
>>>>
>>>> What other solution achieve the same?
>>>
>>> Please see elsewhere in this thread.
>>
>> Well - they do not seem to be on my news server.
>>
>> The only suggestion it carry are yours of:
>> * changing the logic, which may be a good idea, but is definitely
>> not the same
>
> Do you say that because of
>
>> Java does not support any preprocessor
>> flags, but in this case I need a tip for creating a flexiable Java
>> code during the class is compiled
>> (eg: ifdef1 = true => String[] javaarray = {"lib1"})
>
> ? Right, I took the liberty to ignore the specific requirement to change
> the Java code because I consider the ultimate task to solve to only load
> those libs which can be used. Changing the Java code is just one means
> to that end.

Alternative approaches can be very good.

But it is an alternative approach.

>> * use JNI to get the info from the native side, which will
>> require approx. 10 as much code than this
>
> Well, but the solution to use CPP for Java code will probably need a
> similar amount of code - even if it's not in Java but in ant scripts or
> Makefiles. And it will be a dramatic change to the build process. One
> also needs to decide whether to apply CPP to all Java files or just
> selectively to a single one. The first option is probably cleaner from a
> build process point of view but increases the risk of bugs (i.e. if CPP
> starts replacing things in other files that it is not supposed to
> change) while the second solution is an ugly crutch IMHO.

It will require adding 1 line to the makefile/build script.

Arne

[toc] | [prev] | [next] | [standalone]


#8735

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-10-12 07:04 -0700
Message-ID<ji7b9794gabrupbr6ah12lk7grl3b5c103@4ax.com>
In reply to#8711
On Tue, 11 Oct 2011 20:19:18 +0200, Philipp Kraus
<philipp.kraus@flashpixx.de> wrote, quoted or indirectly quoted
someone who said :

>I use within my Java code different external libraries (DLL), so I have 
>create a string array with their names
>so the libraries can be load with System.load / System.loadLibrary.

Recall that   if ( DEBUGGING ) { out. println( "I'm here"); }
generates no code if the static final boolean DEBUGGING is false.
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to 
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web