Where is the C set_flag() function defined?

I have a C program which calls the function set_flag()
It has 2 arguments.
I can not find where it is defined
but
I did find a declaration

void set_flag(int* flag_holder, int flag_position);

There is a bit of discussion here

but no info on what to include to make the function available to gcc

I have grepped my system to death, and it is simply not there

Does anyone know?

1 Like

I would think that since “C and C++” are compiled with “gcc” that any flag
would have to be set in the makefile prefix, and gcc would have to be compiled with the flag set.

1 Like

It is not a compiler flag, it is a C function called set-flag()
It is not in the list of C library functions.
It must be something special, but it is not with the program code
 the progrsm uses it but does not define it?

I notice that your makefile knowledge is expanding. You are getting something out of LFS.

1 Like

Exactly, and if that program is in need of a certain function of “C” then it will be in need of compiling “gcc” with that function.

1 Like

Yes, and I will not touch LFS again, until I have a capable PC for the compilation, Had to rebuild my Gentoo kernel, because of LFS.

2 Likes

Yes. I need to find the code for the function
 or work out what it does and write it.

1 Like

Do not know enough about bash scripts to help with that!!!

2 Likes

Been a while since i wrote any programs, but dont you need to set it to a zero value in déclaration to start with, as depending on the register may not be nuls to start ?

2 Likes

Maybe, but that is not the issue. I cant find the code for the set_flag() function

1 Like

Hi Neville,
Don’t you need to define the function manually?
Trying to understand functions with pointers in C

Jorge

2 Likes

Hi Jorge,

Yes, that is what is needed.
I did not read that link carefully enough, it is there


void set_flag(int* flag_holder, int flag_position){ *flag_holder |= (1 << flag_position); }

I only saw the declaration, and missed the definition.

Last time I compiled this code it was in FreeBSD
 it must have been defined there or the code would not have worked. Linux is a different world when it comes to what is available to the compiler.

Thank you Jorge
Regards
Neville

3 Likes

Hi again Jorge,
Sadly , that is not the version of the set_flag() function that I need.

The one called in my code has arguments
set_flag( Widget, int*)
where Widget is a structure.

It is doing X11 stuff, so I am going to look in X11 libraries.
Maybe I have some missing X11 libraries?

At least you got me past my blind spot
Regards
Neville

2 Likes

Ho Neville,
Can you elaborate a little more on what you want to do with this function and/or add a little more code?

Jorge

1 Like

Here is one of the calls

set_flag(shell,&colorflag);

the arguments are

int colorflag = 0; /* Flag is non-zero if Color menu is mapped */

Widget shell, form, label;
so shell is a variable of type Widget

typedef struct _WidgetRec *Widget;
so Widget is a pointer to _WidgetRec

typedef struct _WidgetRec {
    CorePart    core;
 } WidgetRec, CoreRec; 

and _WidgetRec is a structure

From reading the X Toolkit Intrinsics Programmiong Manual I found out that a ‘shell widget’ is a widget that is the parent of all other widgets.
but
there is no mention in the manual of using set_flag().

I did not write this software. I think what the writer is doing is
inserting a flag directly into one of the X structures , perhaps by OR’ing it with what is already there, perhaps by simply copying it into the shell pointer, ie

*shell = colorflag

or maybe he is doing the reverse, ie setting up the flag

*colorflag = shell

I cant be sure. I need to see the set_flag() function.

This was never an issue when I compiled it in BSD, so I am going back to FreeBSD to see if I can find the set_flag() function.

found only this in FreeBSD

#define SET_FLAG(value, mask, flag)            \
    do {                                       \
        (value) &= ~(mask);                    \
        (value) |= ((flag) << (mask##_SHIFT)); \
    } while (0)

#define GET_FLAG(value, mask)              \
    (((value) & (mask)) >> (mask##_SHIFT))

I dont think that is it, it has 3 arguments.

2 Likes

Where did you get the code from ? Without any hint, it is impossible to even try to find-out what set_flag() could be.
It surely does not come from X11/Xt, as they (normally) use X/Xt prefixes, nor from standard includes, as it references some X structure.
The best bet would be to have a look into code itself, if you can share it (with Makefile, and any other possible configuration file (configure script, CMakeLists.txt, etc
).

2 Likes

It is very old code from Solaris and BSD in 1990’s
I cant share it, it is copyrighted.
I have permission to have a copy for my own use only.

What is really puzzling is that I once had it successfully compiled and running in FreeBSD Version 2.x.
Now in Linux, I have this issue.

I think you are right. It is near impossible to guess what set_flag() might do.

I agree with that.
I think it is writing onto ( or maybe extracting from) some X structure
 directly, bypassing the X functions.

2 Likes

Where did you get the code from ?

It is very old code from Solaris and BSD in 1990’s
I cant share it, it is copyrighted.
I have permission to have a copy for my own use only.

This question was “Where did you get the code from”, and did not imply you need to share the code.
Maybe it could be possible to get the same license as you got, for personal use only ?

1 Like

It is possible, but it is not free. I will think about that. It would get me a more uptodate version.

1 Like

It belongs to my former employer.

1 Like

Oh ok


Good you kept your “personal license” after you quit the job, and did not have to sign a clause asking you to delete any copy of company document/code :wink:

My former employers were more strict there, but as human is fallible


1 Like