ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
within the c file, the two where originally declared within the old (other) C file. I split it, put the definition in to the header file, modded the functions that use this, and got everything back to no errors (so far) leaving me with this one .
Code:
> gcc -m64 -lX11 `imlib2-config --cflags` `imlib2-config --libs` loadimage.c options.c getinfo.c main.c -o tryme
options.c: In function 'mh_parse_options_array':
options.c:218:5: error: a label can only be part of a statement and a declaration is not a statement
Color c;
^
it actually worked one time, then I added another Color c; in a different case off the switch and then it started giving me all of these problems - that I wittled down to just that last one.
I've seen it shown that it can be written like that but without any further example
ie
Code:
Absolutely valid. Usually, you can take full advantage of this way by defining two types together:
typedef struct
{
int a;
int b;
} S1, *S1PTR;
with parse_color uncommended it gets this -- (without saying) due to Color c;
Code:
gcc -m64 -lX11 `imlib2-config --cflags` `imlib2-config --libs` loadimage.c options.c getinfo.c main.c -o tryme
options.c: In function 'mh_parse_options_array':
options.c:231:26: warning: passing argument 2 of 'parse_color' from incompatible pointer type [-Wincompatible-pointer-types]
parse_color (optarg, &c, 255); // alpha = 255
^
options.c:48:5: note: expected 'PColor {aka struct <anonymous> *}' but argument is of type 'Color ** {aka struct <anonymous> **}'
int parse_color (char *optarg, PColor c, int a)
^
options.c:232:31: error: request for member 'r' in something not a structure or union
imlib_context_set_color (c.r, c.g, c.b, c.a);
^
options.c:232:36: error: request for member 'g' in something not a structure or union
imlib_context_set_color (c.r, c.g, c.b, c.a);
^
options.c:232:41: error: request for member 'b' in something not a structure or union
imlib_context_set_color (c.r, c.g, c.b, c.a);
^
options.c:232:46: error: request for member 'a' in something not a structure or union
imlib_context_set_color (c.r, c.g, c.b, c.a);
^
I get one to work but as soon as I un comment the other ones I get errors again as noted.
Code:
> gcc -m64 -lX11 `imlib2-config --cflags` `imlib2-config --libs` loadimage.c options.c getinfo.c main.c -o tryme
options.c: In function 'mh_parse_options_array':
options.c:236:15: error: redeclaration of 'c' with no linkage
Color c;
^
options.c:221:12: note: previous declaration of 'c' was here
Color c;
^
options.c:247:14: error: redeclaration of 'c' with no linkage
Color c;
^
options.c:236:15: note: previous declaration of 'c' was here
Color c;
^
gcc error messages can be terse but the warning and errors in post #3 are pretty clear:
Code:
options.c:231:26: warning: passing argument 2 of 'parse_color' from incompatible pointer type [-Wincompatible-pointer-types]
parse_color (optarg, &c, 255); // alpha = 255
options.c:48:5: note: expected 'PColor {aka struct <anonymous> *}' but argument is of type 'Color ** {aka struct <anonymous> **}'
int parse_color (char *optarg, PColor c, int a)
Think about how you are passing Color ** instead of a Color *.
For post #4 try putting each case with a Color c declaration in its own scope:
gcc error messages can be terse but the warning and errors in post #3 are pretty clear:
Code:
options.c:231:26: warning: passing argument 2 of 'parse_color' from incompatible pointer type [-Wincompatible-pointer-types]
parse_color (optarg, &c, 255); // alpha = 255
options.c:48:5: note: expected 'PColor {aka struct <anonymous> *}' but argument is of type 'Color ** {aka struct <anonymous> **}'
int parse_color (char *optarg, PColor c, int a)
Think about how you are passing Color ** instead of a Color *.
For post #4 try putting each case with a Color c declaration in its own scope:
A typedef merely describes what a Color looks like. You should declare the type only once, e.g. in a header file, before any uses of the type-name are made.
The author's type declarations mean that Color *foo; and PColor foo; are equivalent, because s/he declared that PColor is "pointer to Color."
In C, you cannot declare a variable twice. Some languages have "block scope" for local variables but C does not. It has global variables and local variables. At the start of the function, declare all local variables that will exist in that function. They will be available throughout the function, and, if the function calls itself recursively, will be distinct for each recursive instance.
Last edited by sundialsvcs; 08-02-2017 at 07:57 AM.
A typedef merely describes what a Color looks like. You should declare the type only once, e.g. in a header file, before any uses of the type-name are made.
The author's type declarations mean that Color *foo; and PColor foo; are equivalent, because s/he declared that PColor is "pointer to Color."
In C, you cannot declare a variable twice. Some languages have "block scope" for local variables but C does not. It has global variables and local variables. At the start of the function, declare all local variables that will exist in that function. They will be available throughout the function, and, if the function calls itself recursively, will be distinct for each recursive instance.
I cannot speak for the one that wrote that originally, though it was/is a C program that it is in. that being said. I have no idea why they did it that way, it worked so I wasn't going to mess with it. But it looks like its time to.
Thanks
A typedef merely describes what a Color looks like. You should declare the type only once, e.g. in a header file, before any uses of the type-name are made.
The author's type declarations mean that Color *foo; and PColor foo; are equivalent, because s/he declared that PColor is "pointer to Color."
In C, you cannot declare a variable twice. Some languages have "block scope" for local variables but C does not. It has global variables and local variables. At the start of the function, declare all local variables that will exist in that function. They will be available throughout the function, and, if the function calls itself recursively, will be distinct for each recursive instance.
but looking at this page which is not a typedef strut but just a plane ole stuct
it states
Code:
#include <stdio.h>
#include <string.h>
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};
int main( ) {
struct Books Book1; /* Declare Book1 of type Book */
struct Books Book2; /* Declare Book2 of type Book */
would that not be the same as,
Code:
typedef struct {
int a,b,c,d;
} <tag/name>Color, *PColor; < declared *PColor pointer to type Color.
// side stepping.
Code:
typedef struct Color {
int a,b,c,d;
};
int main()
struct Color *PColor; <-- declared *PColor pointer to type Color.
But errors errors errors is what I get,
Code:
gcc -m64 -lX11 `imlib2-config --cflags` `imlib2-config --libs` loadimage.c options.c getinfo.c main.c -o tryme
options.c:17:1: warning: useless storage class specifier in empty declaration
}; // *PColor;
^
options.c: In function 'mh_parse_options_array':
options.c:250:27: error: 'cl' undeclared (first use in this function)
parse_color (optarg, &cl, 255); // alpha = 255
^
options.c:250:27: note: each undeclared identifier is reported only once for each function it appears in
Code:
typedef struct Color
{
int r, g, b, a;
}; // *PColor;
typedef struct Color *PColor;
gets me this
Code:
options.c:17:1: warning: useless storage class specifier in empty declaration
}; // *PColor;
^
options.c: In function 'mh_parse_options_array':
options.c:250:27: error: 'cl' undeclared (first use in this function)
parse_color (optarg, &cl, 255); // alpha = 255
^
changing it to this
Code:
typedef struct
{
int r, g, b, a;
}Color; // *PColor;
typedef struct Color *PColor;
gets me this:
Code:
ptions.c: In function 'parse_color':
options.c:89:4: error: dereferencing pointer to incomplete type 'struct Color'
cl->r = getHex (optarg[1]) * 16 + getHex (optarg[2]);
^
options.c: In function 'mh_parse_options_array':
options.c:250:27: error: 'cl' undeclared (first use in this function)
parse_color (optarg, &cl, 255); // alpha = 255
^
options.c:250:27: note: each undeclared identifier is reported only once for each function it appears in
BUT when I put it back just like it was beforehand
-- sets the color whatever one picks via hex "#fab123" boom got color on desktop background.
Code:
userx%slackwhere ~ options-pratice > ./tryme -s "#a4f442"
C is 115
In solid color
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex
non-option ARGV-elements: ./tryme -s #a4f442
for two colors
Code:
userx%slackwhere âš¡ options-pratice âš¡>
userx%slackwhere âš¡ options-pratice âš¡> ./tryme --add "#a4f442" -add "#a45542" --gradient 45
C is 200
add
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex
C is 200
add
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex
C is 97
non-option ARGV-elements: ./tryme --add #a4f442 -add #a45542 --gradient 45
in main after parse options 0
in setImage loadimage.c
in setrootatoms
and one more just to show off a little
Code:
> ./tryme --resize-center -g 400x600 --add "#a4f442" --add "#a45542" --gradient 45 --filename /home/userx/slackware_14.jpg
C is 99
C is 103
in findX
mode 11 : width 400 height 600
C is 200
add
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex
C is 200
add
in gethex
in gethex
in gethex
in gethex
in gethex
in gethex
C is 97
C is 110
in case file /home/userx/slackware_14.jpg
non-option ARGV-elements: ./tryme --resize-center -g 400x600 --add #a4f442 --add #a45542 --gradient 45 --filename /home/userx/slackware_14.jpg
in main after parse options 11
in setAlpha
in setImage loadimage.c
in setrootatoms
resized image to whatever I tell it to be with two colors and a gradient -
it works just like it is suppose to.
SOOOOOOo now what ya say about that? Because I have no cue.
An example of what I attempted to explain in post #5:
Code:
#include <stdio.h>
typedef struct Color
{
int r, g, b, a;
} Color;
int main(int argc, char *argv[]) {
Color c = {255, 0, 0, 0};
switch(argc) {
case 0:
{
Color c = {0, 255, 0, 0};
break;
}
case 1:
{
Color c = {127, 0, 255, 64};
printf("case 1 c.r= %d\n", c.r);
break;
}
default:
break;
}
printf("c.r= %d\n", c.r);
}
output:
case 1 - c.r= 127
c.r= 255
Am I doubting? I know hat I see, is nothing but errors when I try it like that, and every other combination I seen in what google had out there and but everything way I tried failed.
It too may be because of the way he wrote the means to gain (retrieve) the information. they way you are showing I've tried and it failed and still does.
the setup
Code:
typedef struct Color
{
int r, g, b, a;
} Color; //, *PColor;
the functions that uses it:
Code:
int getHex (char c)
{
//printf("in gethex\n");
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return c - '0';
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
return c - 'A' + 10;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
return c - 'a' + 10;
default:
return 0;
}// end switch
} // end function
int parse_color (char *optarg, Color co, int a)
{
if (optarg[0] != '#')
return 1;
if ((strlen (optarg) != 7) && (strlen (optarg) != 9))
return 1;
/**pointers **/ co->r = getHex (optarg[1]) * 16 + getHex (optarg[2]);
co->g = getHex (optarg[3]) * 16 + getHex (optarg[4]);
co->b = getHex (optarg[5]) * 16 + getHex (optarg[6]);
co->a = a;
if (strlen (optarg) == 9)
co->a = getHex (optarg[7]) * 16 + getHex (optarg[8]);
return 0;
}
The fails / Errors by declaring it like you say it needs to be.
Code:
options.c:67:4: error: invalid type argument of '->' (have 'Color {aka struct Color}')
co->r = getHex (optarg[1]) * 16 + getHex (optarg[2]);
^
options.c:68:4: error: invalid type argument of '->' (have 'Color {aka struct Color}')
co->g = getHex (optarg[3]) * 16 + getHex (optarg[4]);
^
options.c:69:4: error: invalid type argument of '->' (have 'Color {aka struct Color}')
co->b = getHex (optarg[5]) * 16 + getHex (optarg[6]);
^
options.c:70:4: error: invalid type argument of '->' (have 'Color {aka struct Color}')
co->a = a;
^
options.c:73:5: error: invalid type argument of '->' (have 'Color {aka struct Color}')
co->a = getHex (optarg[7]) * 16 + getHex (optarg[8]);
^
options.c: In function 'mh_parse_options_array':
options.c:217:26: error: incompatible type for argument 2 of 'parse_color'
parse_color (optarg, &co, 255); // alpha = 255
^
options.c:59:5: note: expected 'Color {aka struct Color}' but argument is of type 'Color * {aka struct Color *}'
int parse_color (char *optarg, Color co, int a)
^
options.c:232:30: error: incompatible type for argument 2 of 'parse_color'
if (parse_color (optarg, &co, 255) == 1 ) // alpha = 255
^
options.c:59:5: note: expected 'Color {aka struct Color}' but argument is of type 'Color * {aka struct Color *}'
int parse_color (char *optarg, Color co, int a)
^
options.c:257:26: error: incompatible type for argument 2 of 'parse_color'
parse_color (optarg, &co, 255); // alpha = 255
^
options.c:59:5: note: expected 'Color {aka struct Color}' but argument is of type 'Color * {aka struct Color *}'
int parse_color (char *optarg, Color co, int a)
It has to be due to him using pointers in the parse_color function.
or is it?
Leur est plus qu'une façon de peauter un chat
But definitely thanks for that web link on (data) Scope - I'm now going into my first attempt for a link list. to put filenames with their paths to them in it.
steps:
get path to dir, check dir to be sure it is a dir , open dir, search for files (leave out . and .. then insert path/filename into linked list. close dir.
create function to cycle through list and send information to imlib for processing.
just one, and one after the other, and on a random cycle with a user set time to change image options.
free list when done.
sounds easy but I know I'm going to have errors - that is my (modus operandi) MO
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.